#include <bits/stdc++.h>
#define NMAX 100008
#define MMAX 10008
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
#define forn(a,b,c) for(int a=b;a<c;a++)
#define ford(a,b,c) for(int a=b;a>=c;a--)
int n,m;
int k[NMAX], a[NMAX];
ll resi(int t)
{
    if(t == n)
    {
        ll ans = 0;
        forn(j,0,m)
            ans += (ll)k[j] * (ll)(n - k[j]);
        return ans;
    }
    forn(j,0,m)
    {
        if(j < a[t])
            k[j]++;
    }
    ll rez = resi(t + 1);
    forn(j,0,m)
    {
        if(j >= a[t])
            k[j]++;
        else
            k[j]--;
    }
    rez = min(rez,resi(t + 1));
    forn(j,a[t],m)
        k[j]--;
    return rez;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    forn(i,0,m)
        k[i] = 0;
    forn(i,0,n)
        cin >> a[i];
    cout << resi(0);
    return 0;
}