#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
	int n, k, p = 0, m;
	scanf("%d %d",&n,&k);
	int a[n];
	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]);

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

	printf("%d",abs(m));
}