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

#define long int64_t
#define endl '\n'

#ifdef OFFLINE
	#define logan(...) logg(#__VA_ARGS__, __VA_ARGS__)
	template<class Arg>
	void logg(const char* name, Arg&& arg){ cerr << name << ": " << arg << '\n'; }
	template<class Arg, class ... Args>
	void logg(const char* name, Arg&& arg, Args&& ... args){
		const char* next = strchr(name+1, ',');
		cerr.write(name, next-name) << ": " << arg << ",";
		logg(next+1, args...);
	}
	#define timeme 1.0*clock()/CLOCKS_PER_SEC
#else
	#define logan(...) {}
	#define timeme {}
#endif

long g[101];
long a[101];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	long n, m; cin >> n >> m;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}


	long res = INT64_MAX;
	for(int i = 0; i < (1<<n); ++i){
		memset(g, 0, sizeof g);
		for(int j = 0; j < n; ++j){
			if(i&(1<<j)) for(int k = 0; k < a[j]; ++k) ++g[k];
			else for(int k = a[j]; k < m; ++k) ++g[k];
		}

		long tmp = 0;
		for(int i = 0; i < m; ++i)
			tmp += (n-g[i])*g[i];
		res = min(tmp, res);

	}
	cout << res << endl;


}