#include <bits/stdc++.h>
using namespace std;

int solve(int n, int k, int a[]){
	
	
	int moc = 0;
	int i = 0;
	int j = n - 1;
	
	k--;
	
	while(k > 0){
	
	if(a[i] >= a[j]){
	a[i] -= a[j];
	moc = a[i];
	j--;
	}else{
	 a[j] -= a[i];
	 moc = a[j];
	 i++;
	}
		k--;
	}
		
	
	
	return moc;
	
}

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,k;
	
	cin >> n >> k;
	
	int a[n],b[k];
	
	for(int i = 0; i < n; i++){
		
		cin >> a[i];
		
	}
	
	cout << solve(n,k,a);
	
	return 0;
}