#include <bits/stdc++.h>
using namespace std;

int n, m;
int movs[100000];

long long min_boredom(vector<int> row, int index)
{
	if (index >= n)
	{
		long long res = 0;
		for (int i = 0; i < m; ++i)
			res += (long long)row[i]*(long long)(n-row[i]);
		return res;
	}	
	vector<int> row2 = row;
	for (int i = 0; i < movs[index]; ++i) ++row[i];
	for (int i = movs[index]; i < m; ++i) ++row2[i];
	return min(min_boredom(row, index+1), min_boredom(row2, index+1));

}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; ++i)
		cin >> movs[i];
	vector<int> a(m, 0);
	cout << min_boredom(a, 0) << '\n';
}