using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Carobnjak2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int k = int.Parse(s[1]);
            string[] st = Console.ReadLine().Split();
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(st[i]);
            }
            int p = 0;
            int kr = n - 1;
            for (int i = 0; i < k - 1; i++)
            {
                if (a[p] < a[kr])
                {
                    a[kr] -= a[p];
                    p++;
                }
                else
                {
                    a[p] -= a[kr];
                    kr--;
                }
            }
            Console.WriteLine(a[kr]);
        }
    }
}