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();
            int n = int.Parse(s[0]);
            int k = int.Parse(s[1]);
            s = Console.ReadLine().Split();
            int[] a = new int[n];
            int zbir = 0;
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(s[i]);
                zbir += a[i];
            }
            Console.WriteLine(zbir - 2 * Math.Min(a[0], a[n - 1]));
        }
    }
}