#include <bits/stdc++.h>
using namespace std;

const long long N = 200005;
long long a[N];
long long psl[N];
long long psr[N];

long long solvenk(vector<long long> vek, long long k){
    if(vek.empty() || (long long)vek.size() != k)
        return LLONG_MIN;

    long long n = vek.size();

    psl[0] = vek[0];
    for(long long i = 1; i < n; ++i){
        psl[i] = psl[i - 1] + vek[i];
    }
    psr[n - 1] = vek[n - 1];
    for(long long i = n - 2; i >= 0; --i){
        psr[i] = psr[i + 1] + vek[i];
    }

    long long mxSum = LLONG_MIN;
    for(long long i = 0; i < n - 1; ++i){
        long long s1 = psl[i] - psr[i + 1]; //this lookin kinda recursive
        long long s2 = psr[i + 1] - psl[i];
        mxSum = max(mxSum, max(s1, s2));
    }

    return mxSum;
}

void solvebf(long long n, long long k){
    long long best = LLONG_MIN;
    for(long long mask = 0; mask < (1 << n); ++mask){
        vector<long long> elems;
        for(long long j = 0; j < n; ++j){
            if((1 << j) & mask)
                elems.push_back(a[j]);
        }
        long long x = solvenk(elems, k);
        best = max(best, x);
    }
    cout << best << "\n";
}

int main()
{
    long long n, k;
    cin >> n >> k;
    vector<long long> all;
    for(long long i = 0; i < n; ++i){
        cin >> a[i];
        all.push_back(a[i]);
    }

    if(n == k){
        long long res = solvenk(all, k);
        cout << res << "\n";
        return 0;
    }
    solvebf(n, k);
    return 0;
}