#include <bits/stdc++.h>

#define vl vector<long long>
#define pb push_back

using namespace std;

typedef long long ll;

ll n, m;
vl v;

ll solve(ll a) {
	vl diff(m+1, 0);	
	for (int i = 0; i<n; i++) {
		if (i < a) {
			diff[v[i]]--;
			diff[0]++;
		}
		else 
			diff[v[i]]++;
	}
	ll res = 0, cur = 0;
	for (int i = 0; i<m; i++) {
		cur += diff[i];
		res += cur * (m-cur);
	}
	return res;
}

int main() {
	// hmm mozda ce cpp biti brzi od py
	// hoodlum548<3
	ios_base::sync_with_stdio(false); 
	cin.tie(nullptr), cout.tie(nullptr), cerr.tie(nullptr);
	cin >> n >> m;

	for (int i = 0; i<n; i++) {
		ll x;
		cin >> x;
		v.pb(x);
	}

	sort(v.begin(), v.end());
	ll sol = 1e18 + 5;
	int lo = 0, hi = n;

	for (int i = 0; i<n; i++)
		sol = min(sol, solve(i));
	cout << sol << endl;
	return 0;
}