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

namespace ConsoleApplication27
{
    class Program
    {
        static void Main(string[] args)
        {
            int br=0;
            string un=Console.ReadLine();
            int n = int.Parse(un.Split()[0]);
            int m = int.Parse(un.Split()[1]);
            int[,] matr = new int[n, m];
            int[] niz = new int[n];
            for(int i=0;i<n;i++)
            {
                niz[i] = int.Parse(Console.ReadLine());
                if (niz[i] == m || niz[i]==0)
                    br = br + 1;
            }
            if(br>0)
            {
                int[] uf = new int[n - br];
                int k=0;
                for (int i = 0; i < n; i++)
                {
                    if (niz[i] != m && niz[i]!=0)
                    {
                        uf[k] = niz[i];
                        k++;
                    }
                }
                int br1 = 0;
                for (int i = 0; i < k; i++)
                {
                    if (uf[i]> m/2)
                    {
                        br1++;
                    }
                }
                if(br1> n/2)
                {
                    for(int i=0;i<n;i++)
                    {
                        for(int j=0;j<m;j++)
                        {
                            if (niz[i] > j)
                                matr[i, j] = 1;
                            else
                                matr[i, j] = 0;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < n; i++)
                    {
                        for (int j = 0; j < m; j++)
                        {
                            if (niz[i] > j && niz[i]!=0 && niz[i]!=n)
                                matr[i, j] = 1;
                            else
                                matr[i, j] = 0;
                        }
                    }
                }

            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        if (niz[i] > j)
                            matr[i, j] = 1;
                        else
                            matr[i, j] = 0;
                    }
                }
            }
            int res=0;
            for (int j = 0; j < m; j++)
            {
                int zb=0;
                for (int i = 0; i < n; i++)
                {
                    zb += matr[i, j];
                }
                res += zb * (n - zb);
            }
            Console.WriteLine(res);
        }
    }
}