#include <iostream>
#include <vector>

using namespace std;

int getMaxP(vector<int> order) {
    int minP = min(order.at(0), order.at(order.size()-1));
    int res = 0;
    for(int i = 0; i < order.size(); i++) res += order.at(i);

    return res - 2 * minP;
}

int getOrder(vector<int> order, int K, int N, int a[], int i, vector<bool> used) {
    if(K == 0) return getMaxP(order);
    else {
        used.at(i) = true;
        int res = 0;
        for(int j = i + 1; j < N; j++) {
            order.push_back(a[j]);
            if(!used.at(j)) res = max(res, getOrder(order, K - 1, N, a, j, used));
            order.pop_back();
        }
       return res;
    }
}

int main()
{
    int K, N;
    cin >> N >> K;
    int a[N];
    for(int i = 0; i < N; i++){
        int x;
        cin >> x;
        a[i] = x;
    }

    int res = 0;
    for(int i = 0; i < N; i++){
       vector<int> order;
       vector<bool> used;
       for(int i = 0; i < N; i++) used.push_back(false);
       used.at(i) = true;
       order.push_back(a[i]);
       res = max(res, getOrder(order, K-1, N, a, i, used));
    }

    cout << res;
}