using System;

namespace Takmicenje_2___18._12._2021_
{
    class Program
    {
        static int maks = 0;
        static void Pronadji(int[] napici, int k)
        {
            int[] novi_niz = new int[k];
            novi_niz[0] = napici[0];
            maks = napici[0];
            for (int i=1;i<k;i++)
            {
                novi_niz[i] = napici[napici.Length - (k-i)];
            }
            Otrov(novi_niz);
        }
        static void Otrov(int[] novi_niz)
        {
            for (int i=1;i<novi_niz.Length-1;i++)
            {
                novi_niz[i + 1] = novi_niz[i] - novi_niz[i + 1];
            }
            maks -= novi_niz[novi_niz.Length - 1];
        }
        static void Main(string[] args)
        {
            string[] red = Console.ReadLine().Split();
            int n = Convert.ToInt32(red[0]);
            int k = Convert.ToInt32(red[1]);
            string[] red2 = Console.ReadLine().Split();
            int[] napici = new int[n];
            for (int i = 0; i < n; i++)
            {
                napici[i] = Convert.ToInt32(red2[i]);
            }
            Array.Sort(napici);
            Array.Reverse(napici);
            Pronadji(napici, k);
            Console.WriteLine(maks);
        }
    }
}