#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    int niz[n];
    for (int i = 0; i < n; i++)
    {
        cin >> niz[i];
    }
    sort(niz, niz + n);
    /*for (int i = 0; i < n; i++)
    {
        cout << niz[i] << endl;
    }*/
    int i = 0, j = n - 1, brojac = 1;
    int napitak = niz[i];
    while (i != j && brojac < k)
    {
        if (niz[i] - niz[j] > niz[j] - niz[i])
        {
            niz[i] -= niz[j];
            j--;
            napitak = niz[i];
            //cout << 1 << endl;
        }
        else
        {
            niz[j] -= niz[i];
            i++;
            napitak = niz[j];
            //cout << 2 << endl;
        }
        brojac++;
    }
    i++;
    cout << napitak;
    return 0;
}