using System;
using System.Collections.Generic;

    class Program
    {
        static void Main(string[] args)
        {
            var x = Console.ReadLine().Split(' ');
            int n = int.Parse(x[0]);
            int k = int.Parse(x[1]);
            int[] a = new int[n];
            int r = 0;
            var y = Console.ReadLine().Split(' ');
            List<int> l = new List<int>();
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(y[i]);
                l.Add(a[i]);
            }
            while (k - 1 > 0)
            {
                if (l[0] > l[k])
                {
                    r = l[0] - l[k];
                    l.RemoveAt(0);
                }
                else
                {
                    r = l[k] - l[0];
                    l.RemoveAt(k);
                }
                k--;
            }
            Console.WriteLine(r);
        }
    }