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

namespace kvalifikacija2
{
    class Program
    {
        static int[] BinP(int[] a)
        {
            bool k = false;
            if (a[a.Length - 1] == 0)
                a[a.Length - 1] = 1;
            else
            {
                a[a.Length - 1] = 0;
                k = true;
            }
            for(int i = a.Length - 2; i >= 0; i --)
            {
                if (k)
                {
                    if (a[i] == 1)
                        a[i] = 0;
                    else
                    {
                        k = false;
                        a[i] = 1;
                    }
                }
                else
                    break;
            }
            return a;
        }
        static void Main(string[] args)
        {
            string[] k;
            string s;
            int n, m;
            k = Console.ReadLine().Split();
            n = Convert.ToInt32(k[0]);
            m = Convert.ToInt32(k[1]);
            int w = 0, f = 0, nf = 0, mw = (n - 1) * m;
            int[] q = new int[n];
            for(int i = 0; i < n; i ++)
            {
                s = Console.ReadLine();
                q[i] = Convert.ToInt32(s);
            }
            int[,] a = new int[n, m];
            int[] p = new int[n];
            for (int i = 0; i < n; i++)
                p[i] = 0;
            for(int t = 0; t < Math.Pow(2.0, Convert.ToDouble(n)); t ++)
            {
                for (int i = 0; i < n; i++)
                {
                    if (p[i] == 0)
                    {
                        for (int j = 0; j < q[i]; j++)
                            a[i, j] = 1;
                        for (int j = q[i]; j < m; j++)
                            a[i, j] = 0;
                    }
                    else
                    {
                        int l = m - q[i];
                        int l1 = m - 1;
                        for (int j = 0; j < l; j++)
                            a[i, l1 - j] = 1;
                        for (int j = l1 - l; j >= 0; j--)
                            a[i, j] = 0;
                    }
                }
                for(int i = 0; i < m; i ++)
                {
                    for(int j = 0; j < n; j ++)
                    {
                        if (a[j, i] == 1)
                            f++;
                        else
                            nf++;
                    }
                    w += f * nf;
                    f = nf = 0;
                }

                if (w < mw)
                    mw = w;
                f = 0;
                nf = 0;
                w = 0;
                BinP(p);
            }
            Console.WriteLine(mw);
            Console.ReadKey();
        }
    }
}