#include<iostream>

using namespace std;

int main()
{
	int dosadnost=0;
	int n,m;
	int b1=0;
	int b2=0;
	cin>>n>>m;
	int matrica[n][m];
	int a[n];
	int j;
	for(int k = 0;k<n;k++)
	{
		cin>>a[k];
	}
	
	for(int i = 0;i<n;i++)
	{
		for(j = 0;j<m;j++)
		{			
			if(j<a[i]) 
			{
				matrica[i][j]=1;
			}		
			else 
			{
				matrica[i][j]=0;
			}	
		
			if(i != 0)
			{
				if(matrica[i][j] == matrica[i-1][j])
				{
					b1++;
				}
				else 
				{
					b2++;
				}
			}		
		}	
		if(b1!=0 || b2!=0)
		{
			if(b1<=b2)
			{
				j = 0;
				while(j<m)
				{
					if(j>=a[i]) 
					{
						matrica[i][j]=1;
					}		
					else 
					{
						matrica[i][j]=0;
					}
					j++;	
				}
			}		
		}
		
		b1=0;
		b2=0;
	}
	//provera
	int mb1=0,mb2=0;
	for(int t = 0;t<m;t++)
	{
		for(int z = 0;z<n;z++)
		{
			if(matrica[z][t] == 1) mb1++;
			else mb2++;
		}
		dosadnost+=mb1*mb2;
		mb1=0;
		mb2=0;
	} 
	
	cout<<dosadnost;
	
	return 0;
}