using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static int moc(int[] a)
        {
            int n = a.Length;
            int zbir = Math.Abs(a[0] - a[n - 1]);
            for (int i = 1; i < n - 1; i++)
                zbir += a[i];
            return zbir;
        }
        static void Main(string[] args)
        {
            String[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int k = int.Parse(s[1]);
            int[] a = new int[n];
            String[] s1 = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
                a[i] = int.Parse(s1[i]);
            int max = 0;
            int[] index = new int[k];
            for (int i = 0; i < k; i++)
                index[i] = i;
            int poz = k - 1;
            while (index[0] <= n - k)
            {
                int[] niz = new int[k];
                for (int i = 0; i < k; i++)
                    niz[i] = a[index[i]];
                int mo = moc(niz);
                if (mo > max)
                    max = mo;
                while (true)
                {
                    if (index[poz] < n - 1)
                    {
                        index[poz]++;
                        break;
                    }
                    else
                    {
                        poz--;
                        break;
                    }
                }
                
            }
            Console.WriteLine(max);
            
        }
    }
}