#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define mid(l, r) ((l)+(r))/2
#define len(a) (a).length()
#define sz(a) (a).size()
#define xx first
#define yy second
#define inf int(2e9)
#define ff(i, a, b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i, a, b) for(int (i) = (a); (i) >= (b); --(i))


using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

template<class T>
void print(const T niz[], const int siz)
{
    for(int i=0;i<siz;i++)
        cout << niz[i] << " ";
    cout << endl;
}

int n,m;
int niz[30];
int sol = 1e9;
int res[30];
int kol[30];
void resi(int i){
    if(i == n){
        ff(j,0,m-1)
            kol[j] = 0;
        ff(j,0,n - 1){
            ff(k,0, m-1){
                if(k < niz[j]){
                    if(res[j] == 0)
                        kol[k]++;
                }
                else if(res[j] == 1)
                    kol[k]++;
            }
        }
        int trres = 0;
        ff(j,0,m-1){
            trres += (kol[j] * (n - kol[j]));
        }
        sol =  min(sol, trres);
        return;
    }
    res[i] = 0;
    resi(i + 1);
    res[i] = 1;
    resi(i + 1);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    ff(i,0,n-1){
        cin >> niz[i];
    }
    resi(0);
    cout << sol;
    return 0;
}