#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);
    int i = 0, j = n - 1, brojac = 0;
    while (i != j && brojac <= k)
    {
        if (niz[i] - niz[j] > niz[j] - niz[i])
        {
            niz[i] -= niz[j];
            j--;
        }
        else
        {
            niz[j] -= niz[i];
            i++;
        }
        brojac++;
    }
    int napitak = niz[i];
    i++;
    while (i <= j)
    {
        napitak = max(napitak, niz[i]);
        i++;
    }
    cout << niz[napitak];
    return 0;
}