#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int binarySearch(int arr[], int l, int r, int x)
{
    if (r >= l)
    {
        int mid = l + (r - l) / 2;

        if (arr[mid] == x)
            return mid;

        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);

        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
int main()
{
    //n - ukupan broj napitaka
    //k - broj uzetih napitaka
    int n, k, minp, maxp, l, u;
    cin >> n >> k;
    int a[n], h[n];

    cin >> a[0] >> a[1];
    if(a[0] > a[1])
    {
        maxp = a[0];
        minp = a[1];
    }
    else
    {
        maxp = a[1];
        minp = a[0];
    }
    for(int i = 2; i < n; i++)
    {
        cin >> a[i];
        if(a[i] > maxp)
            maxp = a[i];
        if(a[i] < minp)
            minp = a[i];
    }
    if(k == 2)
        cout << maxp-minp << endl;
    else
    {
        maxp = 0;
        for(int i = 1; i < k; i++)
            maxp+= a[i];
        maxp-= a[0];

        for(int i = 0; i < n; i++)
        {
            h[i]=a[i];
        }
        sort(h, h+n);
        for(int i = n-1; i >= k; i--)
        {
            l = 0 - a[i];
            a[i] = 0;

            u = binarySearch(h, 0, n-1, l);
            h[u] = 0;
            for(int p = 0; p < k - 1; p++)
                l+= h[p];
            if(l > maxp)
                maxp = l;
        }
        cout << maxp << endl;
    }

    return 0;
}