#include <bits/stdc++.h>

using namespace std;

#define int ll
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

bool mark[31];

vector<vi> b;

void F(int k, int n){
	vi c;
    if (k > n){
        for (int i = 1; i <= n; i++){
            if (mark[i]) 
            	c.push_back(i - 1);
        }
        b.push_back(c);
        return;
    }
    mark[k] = false;
    F(k + 1, n);
    mark[k] = true;
    F(k + 1, n);
}

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

	int n, m;
	cin >> n >> m;  

	vi a(n);
	for (auto& i : a)
		cin >> i;

	F(1, n);

	int sol = INT32_MAX;
	for (auto& k : b){
		vector<vi> c(n, vi(m, 0));

		for (auto& j : k){
			for (int br = 0; br < a[j]; ++br){
				c[j][br] = 1;
			}
		}

		for (int i = 0; i < n; ++i){
			if (!c[i][0]){
				for (int br = 0; br < m - a[i]; ++br){
					c[i][m - br - 1] = 1;
				}
			}
		}

		int rez = 0;
		for (int j = 0; j < m; ++j){
			int res = 0;
			for (int i = 0; i < n; ++i){
				res += c[i][j];
				//cout << c[i][j] << ' ';
			}
			//cout << endl;

			rez += res * (n - res);
		}
		sol = min(sol, rez);
	}

	cout << sol << '\n';
}