#include <iostream>

using namespace std;

int main()
{
    int n;
    int m;
    cin >> n;
    cin >> m;
    int *a = new int[n + 1];
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    int *b = new int[m + 1];
    int *c = new int[m + 1];
    for(int j = 1; j <= m; j++)
    {
        b[j] = 0;
        c[j] = 0;
        for(int h = 1; h <= n; h++)
        {
            if(j <= a[h]) b[j]++;
            if (j > a[h] || a[h] == m) c[j]++;
        }
    }
    int x1 = 0;
    int x2 = 0;
    for(int v = 1; v <= m; v++)
        {
            x1 += b[v] * (n - b[v]);
            x2 += c[v] * (n - c[v]);
        }
    if(x1 < x2) cout << x1;
    else cout << x2;
    delete (a);
    delete (b);
    delete (c);
    return 0;
}