#include <iostream>
#include <vector>
#include <algorithm>

int N, M;
std::vector<int> B;
unsigned long long d, MIN = -1;

void bojenje(std::vector<int> &A, int p);

int main()
{
	std::cin >> N >> M;
	B.assign(M, 0);
	std::vector<int> A(N);
	for (int i = 0; i < N; i++) std::cin >> A[i];
	bojenje(A, 0);
	std::cout << MIN;
	return 0;
}

void bojenje(std::vector<int> &A, int p)
{
	if (p == N)
	{
		d = 0;
		for (int i = 0; i < M; i++) d += (N - B[i])*B[i];
		MIN = std::min(MIN, d);
		return;
	}
	for (int i = 0; i < A[p]; i++) B[i]++;
	bojenje(A, p + 1);
	for (int i = 0; i < A[p]; i++) B[i]--;
	for (int i = M - A[p]; i > 0; i--) B[M - i]++;
	bojenje(A, p + 1);
	for (int i = M - A[p]; i > 0; i--) B[M - i]--;
}