#include<iostream>

using namespace std;

int main()
{
	long int N, M;
	long int A[100];
	long int b[100];
	long int max = 0, s = 0,min=100;

	cin >> N >> M;
	for (int i = 0; i < N; i++)
	{
		cin>> A[i];
		if (A[i] > max) max = A[i];
		if (A[i] < min) min = A[i];
		b[A[i]] = A[i];
	}
	for (int i = min; i <= max; i++)
	{
		b[i] = max - b[i];
		s +=b[i] * (N - b[i]);
	}
	cout << s;
	return 0;
}