#include <stdio.h>
#include <stdlib.h>

void popuni(int** x, int* p, int d, int n, int m);
int izbroj_kolonu(int** a, int i, int n);

void main(){
	int n, m, s = 0, q = 0;
	int i, j, desno = 0, dosadnost = 0;
	int **x, *p;
	scanf("%i%i", &n, &m);
	x = malloc(n * sizeof *x);
	p = malloc(n * sizeof *p);
  	for(i = 0; i < n; i++){
		x[i] = malloc(m * sizeof *x[i]);
		scanf("%i", &p[i]);
		if(p[i] > m - p[i] && p[i] != m && p[i] != 0)
			s += 1;
		if(p[i] == m || p[i] == 0)
			q += 1;
	}
	if(s >= n - q - 1)
		desno = 1;
	popuni(x, p, desno, n, m);
	for(j = 0; j < m; j++)
		dosadnost += izbroj_kolonu(x, j, n);
	printf("%i", dosadnost);
}

int izbroj_kolonu(int** x, int i, int m){
	int j, c = 0, d = 0;
	for(j = 0; j < m; j++){
		if(x[j][i])
			c++;
		else
			d++;
	}
	return c * d;
}

void popuni(int** x, int* p, int d, int n, int m){
	int i, j;
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			if(p[i] == m || p[i] == 0)
				x[i][j] = 0;
			else if((d && j >= p[i]) || (!d && j < p[i]))
				x[i][j] = 1;
			else
				x[i][j] = 0;
		}
	}
}