using System;

namespace ConsoleApp40
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s1 = Console.ReadLine().Split();
            int n = int.Parse(s1[0]);
            int k = int.Parse(s1[1]);
            string[] s2 = Console.ReadLine().Split();
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = int.Parse(s2[i]);
            int p = 0;
            int z = 1;
            int x = 0;
            for (int i = 0; i < k-1; i++)
            {
                if (a[0 + p] - a[n - z] > a[n - z] - a[0 + p])
                {
                    x = a[0 + p] - a[n - z];
                    a[0 + p] = x;
                    z++;
                }
                else if (a[p] - a[n - z] < a[n - z] - a[p])
                {
                    x = a[n - z] - a[p];
                    a[n - z] = x;
                    p++;
                }
            }
            Console.WriteLine(x);
        }
    }
}