#include <iostream>

using namespace std;

int main()
{
    int n, k, pom;

    cin >> n >> k;

    k = k-1;

    int a[n];

    for(int i = 0; i < n; i++){

        cin >> a[i];
    }

    int l = 0;

    int m = n-1;

    for(int i = 0; i < k; i++){

        if(a[l]<a[m]){
            a[m] = a[m] - a[l];
            pom = a[m];
            l++;
        }
        else if(a[l]>a[m]){
            a[l] = a[l] - a[m];
            pom = a[l];
            m--;
        }
    }

    cout << pom << endl;

    return 0;
}