using System;
using System.Collections;
using System.Collections.Generic;

class g
{
    static public int br, n, k;
    static public int[] a, b;
}

class HelloWorld
{
    static void racunaj(int[] a)
    {
        int[] a1 = new int[a.Length];
        for (int i = 0; i < a.Length; i++) a1[i] = a[i];
        for (int i=0;i<a1.Length;i++)Console.Write(a1[i]);Console.WriteLine(" / niz");
        int k = 0,j=a1.Length-1;
        while (k + 1!= j)
        {
            if (a1[k] < a1[j])
            {
                a1[k] -= a1[j];
                j--;
            } else
            {
                a1[j] -= a1[k];
                k++;
            }
        }
        int x = Math.Max(a1[j]-a1[k],a1[k]-a1[j]);
        Console.WriteLine("X je: " + x);
        if (g.br < x) g.br = x;
    }
    static void komb(int[] b, int br, int j)
    {
        if (br == g.k)
        {
            racunaj(b);
        }
        else
        {
            for (int i = j; i < g.n; i++)
            {
                b[br] = g.a[i];
                komb(b, br + 1, i + 1);
            }
        }
    }
    static void Main()
    {
        g.br = -2000000000;
        string[] s = Console.ReadLine().Split(' ');
        g.n = int.Parse(s[0]);
        g.k = int.Parse(s[1]);
        g.a = new int[g.n];
        int[] b = new int[g.k];
        s = Console.ReadLine().Split(' ');
        for (int i = 0; i < g.n; i++)
        {
            g.a[i] = int.Parse(s[i]);
        }
        komb(b, 0, 0);
        Console.WriteLine(g.br);
    }
}