#include<bits/stdc++.h>
#define ll long long
using namespace std;
deque<ll> ar;
ll n,k,t;
int main()
{
	cin >> n >> k;
	for(int i=0;i<n;i++){
		cin >> t;
		ar.push_back(t);
	}
	while(ar.size()>k)
	{
		if(ar[0]>ar[ar.size()-1])ar[0]-=ar[ar.size()-1],ar.pop_back();
		else ar[ar.size()-1]-=ar[0],ar.pop_front();
	}
	sort(ar.begin(),ar.end());
	cout << ar[k-1] << "\n";
}