#include <bits/stdc++.h>

using namespace std;

unsigned long long mini=LONG_MAX;

vector<int> a;

void binarni(string s,int lenght,int n,int m)
{
     if(mini==0)
        return;
        
    if(lenght==0)
        {
            unsigned long long 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+=curr*(n-curr);
            }
            if(cnt<mini)
                mini=cnt;
        }
    else
    {
        binarni(s+'0',lenght-1,n,m);
        binarni(s+'1',lenght-1,n,m);
    }
}

int main()
{
    int n,m;
    cin >> n >> m;
    a.resize(n);
    for(int i=0;i<n;++i)
        cin >> a[i];
    binarni("",n,n,m);
    cout << mini << endl;

    return 0;
}