#include <iostream>

using namespace std;

int main()
{
    int K, N, moc = 0, br;
    cin >> N >> K;
    int a[100000];
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    int i = 0, j = N;
    while (K - 1 != 0) 
    {
        i++; j--; K--;
{
        if (a[i] >= a[j]) {
            if (moc >= a[i]) {
            moc = moc - a[i];
        }
        else {
            moc = a[i] - moc;
        }
        }
        else {
            if (moc >= a[j]) {
            moc = moc - a[j];
        }
        else {
            moc = a[j] - moc;
        }
        }
    }
    br++;
}
cout << moc << endl;
}