using System;
using System.Collections.Generic;
using System.Linq;

namespace MyApp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string[] inp = Console.ReadLine().Split(' ');
            int k = int.Parse(inp[1]);
            int n = int.Parse(inp[0]);
            int[] napici = new int[n];
            string[] np = Console.ReadLine().Split(' ');
            for(int i = 0; i < n; i++) napici[i] = int.Parse(np[i]);
            for (int i = 0; i < k - 1; i++)
            {
                if(napici[0] - napici[n - 1] > napici[n - 1] - napici[0])
                {
                    napici[0] = napici[0] - napici[n - 1];
                    int[] temp = napici;
                    n--; napici = new int[n];
                    for (int j = 0; j < n; j++) napici[j] = temp[j];
                }
                else
                {
                    napici[n - 1] = napici[n - 1] - napici[0];
                    int[] temp = napici;
                    n--; napici = new int[n];
                    for (int j = 1; j < n; j++) napici[j--] = temp[j];
                }
            }
            int max = int.MinValue;
            for (int i = 0; i < n; i++)
                if (napici[i] > max) max = napici[i];
            Console.WriteLine(max);
        }
    }
}