using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Carobnjak
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetIn(new StreamReader(Console.OpenStandardInput(), Console.InputEncoding, false, 2097152));
            string[] s = Console.ReadLine().Split();
            long n = long.Parse(s[0]);
            long k = long.Parse(s[1]);
            s = Console.ReadLine().Split();
            long[] a = new long[n];
            long zbir = 0;
            for (long i = 0; i < n; i++)
            {
                a[i] = long.Parse(s[i]);
                zbir += a[i];
            }
            Console.WriteLine(zbir - 2 * Math.Min(a[0], a[n - 1]));
        }
    }
}