#include <iostream>
#include <cmath>

using namespace std;

/*void printizabrani_brojevi(int izabrani_brojevi[], int n)
{
    for (int i = 0; i < n; i++){
        cout << izabrani_brojevi[i] << " ";
    }
    cout << endl;
}
*/
int rez (int a[], int k)
{
    int ret = abs(a[0] - a[k - 1]);
    for (int i = 1; i < k - 1; i++){
        ret = ret + a[i];
    }

    return ret;
}

void cu(int arr[], int izabrani_brojevi[],int pocetak, int kraj,int loc, int r);


void nadjires(int arr[], int n, int k)
{

    int izabrani_brojevi[k];


    cu(arr, izabrani_brojevi, 0, n-1, 0, k);
}


int mx_rez = sqrt(2), cur_rez;

void cu(int arr[], int izabrani_brojevi[], int pocetak, int kraj, int loc, int k)
{

    if (loc == k)
    {
        for (int j = 0; j < k; j++)
            cur_rez = rez(izabrani_brojevi, k);
            if (mx_rez == sqrt(2)){
                mx_rez == cur_rez;
            }

            else {
                if (cur_rez > mx_rez){
                    //cout << cur_rez << "(cur_rez), " << mx_rez << "(mx_rez)" << endl;
                    mx_rez = cur_rez;
                    //printizabrani_brojevi(izabrani_brojevi, k);

                }

            }
        return;
    }


    for (int i = pocetak; i <= kraj && kraj - i + 1 >= k - loc; i++)
    {
        izabrani_brojevi[loc] = arr[i];
        cu(arr, izabrani_brojevi, i + 1, kraj, loc + 1, k);
    }
}

int main()
{
    int arr[200000], n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++){
        cin >> arr[i];
    }
    if (n - k > k){
        k = n - k;
    }
    nadjires(arr, n, k);
    cout << mx_rez;
}