using System;
using System.Collections.Generic;

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int K = int.Parse(input[1]);
            input = Console.ReadLine().Split(' ');
            List<int> list = new List<int>();
            for (int i = 0; i < N; i++)
            {
                list.Add(int.Parse(input[i]));
            }
            List<int> sortedList = list;
            sortedList.Sort();
            for (int i = 0; i < list.Count; i++)
            {
                for (int j = 0; j < K / 2; j++)
                {
                    if (list[i] != sortedList[j])
                        list.Remove(sortedList[i]);
                }
            }
            for (int i = list.Count; i --> 0;)
            {
                for (int j = sortedList.Count; j < K / 2 + K % 2; j--)
                {
                    if (list[i] != sortedList[j])
                        list.Remove(sortedList[i]);
                }
            }
            for (int i = 0; i < K-1; i++)
            {
                list[0] -= list[list.Count - 1];
                list.RemoveAt(list.Count - 1);
            }
            Console.WriteLine(Math.Abs(list[0]));
        }
    }
}