using System;

namespace Takmicenje20
{
    class Program
    {
        static int operacija1(int x, int y)
        {
            return x - y;
        }
        static int maks(int x, int y)
        {
            if (x > y) return x;
            else return y;
        }

        static void car(int[] a, int n, int k)
        {
            int z = n - 1, max = 0;
            for(int i = 0; i < k / 2; i++)
            {
                max = maks(operacija1(a[0], a[z]), operacija1(a[z], a[0]));
                a[0] = max;
                a[z] = -1000;
                z--;
            }
            Console.WriteLine(max);
        }

        static void Main(string[] args)
        {
            string[] r = Console.ReadLine().Split();
            int n = int.Parse(r[0]);
            int k = int.Parse(r[1]);
            int[] a = new int[n];
            r = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(r[i]);
            }

            car(a, n, k);
        }
    }
}