#include<iostream>
#include<cstdio>

using namespace std;

int main(){
int n,k;
scanf("%d%d",&n,&k);
int a[n];
for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
}
int i=0,j=n-1;
while(k!=1){
   if(a[i]>a[j]){
    a[i]-=a[j];
    j--;
   }
   else{
    a[j]-=a[i];
    i++;
   }
   k--;
}
printf("%d",a[j-i]);
return 0;
}