using System;
using System.Collections.Generic;

namespace Carobnjak
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            string[] r = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int k = int.Parse(s[1]);
            List<int> c = new List<int>();
            for (int i = 0; i < n; i++)
            {
                c.Add(int.Parse(r[i]));
            }
            if (n == k)
            {
                for (int i = 0; i < k-1; i++)
                {
                    if (c[0] - c[c.Count] > 0)
                    {
                        c[0] = c[0] - c[c.Count];
                        c.RemoveAt(c.Count);
                    }
                    else
                    {
                        c[c.Count] = c[c.Count] - c[0];
                        c.RemoveAt(0);
                    }
                }
            }
            else
            {
                int i = 0;
                while (k!=c.Count)
                {
                    if (Math.Abs(c[i]-c[c.Count-i])> Math.Abs(c[i] - c[c.Count-i-1]))
                    {
                        c.RemoveAt(c.Count-i-1);
                    }
                    else
                    {
                        c.RemoveAt(c.Count - i);
                    }
                    i++;continue;
                }
                for (int j = 0; j < k-1; j++)
                {
                    if (c[0] - c[c.Count] > 0)
                    {
                        c[0] = c[0] - c[c.Count];
                        c.RemoveAt(c.Count);
                    }
                    else
                    {
                        c[c.Count] = c[c.Count] - c[0];
                        c.RemoveAt(0);
                    }
                }
            }
        }
    }
}