#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> order_set;
mt19937 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count());
uniform_int_distribution<int> gen(-5, 5); ///(min, max)
int random() {return gen(mt_rand);}
const int mxN = 1e6+5;
const int mod = 998244353;
const int mxlogN = 20;
const int mxK = 26;
const ll inf = 1e9;

int a[mxN];
int b[mxN];
int solve(int l, int r)
{
    if(l==r) return a[l];
    a[r] -= a[l];
    int best = solve(l+1, r);
    a[r] += a[l];
    a[l] -= a[r];
    best = max(best, solve(l, r-1));
    a[l] += a[r];
    return best;
}
int chose(int i, int j, int n, int k)
{
    if(j==k) return solve(0, k-1);
    if(i==n) return -1e9;
    a[j] = b[i];
    int mx = chose(i+1, j+1, n, k);
    mx = max(mx, chose(i+1, j, n, k));
    return mx;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k; cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> b[i];
    cout << chose(0, 0, n, k) << "\n";
}