#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>

#define ll long long

using namespace::std;

ll maxr1 = LLONG_MIN;
vector<ll> pom;

void reccall(vector<ll>& a, int pos, int& k) {
    if (pom.size() == k) {
        ll mbr = (ll)1 << (k - 1);
        ll br = 0;
        ll pombr;
        int l = 0, r = k - 1;
        vector<ll> pom2;
        while (br < mbr) {
            pombr = br;
            pom2 = vector<ll>(pom);
            l = 0, r = k - 1;
            for (int i = 0; i < k - 1; i++) {
                if (pombr % 2) pom2[r] -= pom2[l++];
                else pom2[l] -= pom2[r--];
                pombr /= 2;
            }
            maxr1 = max(maxr1, pom2[l]);
            br++;
        }
    }
    else {
        for (int i = pos; i < a.size(); i++) {
            pom.push_back(a[i]);
            reccall(a, i + 1, k);
            pom.pop_back();
        }
    }
}

void solve() {
    int n, k; cin >> n >> k;
    vector<ll> a(n); for (auto& i : a) cin >> i;
    if (n <= 10) {
        reccall(a, 0, k);
        cout << maxr1 << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    solve();
    return 0;
}