#include <bits/stdc++.h>

using namespace std;

#define MAX 100000

int main()
{
    long long int n,k,a[MAX];
    cin >> n >> k;
    vector <long long int> c;
    for(long long int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    long long int sum = 0;
    if(k == 1)
    {
        sort(a,a+n);
        reverse(a,a+n);
        cout << a[0];
    }
    else if(k >= 2)
    {
        for(long long int i = 0; i <= n-k; ++i)
        {
            for(long long int j = i+k-1; j < n; ++j)
            {
                long long int temp = 0;
                temp = abs(a[i]-a[j]);
                for(long long int r = i+1; r < j; ++r)
                {
                    c.push_back(a[r]);
                }
                sort(c.begin(), c.end());
                reverse(c.begin(), c.end());
                for(long long int r = 0; r < k-2; ++r)
                {
                    temp += c[r];
                }
                if(sum < temp)
                    sum = temp;
                c.clear();
            }
        }
    }
    cout << sum;
    return 0;
}