#include <bits/stdc++.h>

using namespace std;

vector<string> svi;

void binarni(string s,int lenght)
{
    if(lenght==0)
        svi.push_back(s);
    else
    {
        binarni(s+'0',lenght-1);
        binarni(s+'1',lenght-1);
    }
}

int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    for(int i=0;i<n;++i)
        cin >> a[i];
    binarni("",n);
    unsigned long long int cnt=0;
    unsigned long long int min=LONG_MAX;
    for(auto s:svi)
    {
        cnt=0;
        for(int i=0;i<m;++i)
        {
            int curr=0;
            for(int j=0;j<n;++j)
            {
                if(s[j]=='0' && a[j]>i)
                    ++curr;
                else if(s[j]=='1' && a[j]<=i)
                    ++curr;

            }
            cnt+=(n-curr)*curr;
        }
        if(cnt<min)
            {min=cnt;}
        if(min==0)
            break;
    }
    cout << min;
    return 0;
}