#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 100005
typedef long long ll;


using namespace std;
ll n,m;
ll niz[MAXN];
ll svipre[MAXN];
ll sviposle[MAXN];
ll provera(ll mid){
    ll tres=0;
    for(ll i=1;i<=m;i++){
        //printf(" %lld %lld\n",min(mid,svipre[i])+min(n-mid,sviposle[i]),(n-min(mid,svipre[i])-min(n-mid,sviposle[i])));
        tres+=(min(mid,svipre[i])+min(n-mid,sviposle[i]))*(n-min(mid,svipre[i])-min(n-mid,sviposle[i]));
    }
    //printf("   %lld     %lld\n",mid,tres);
    return tres;
}


ll ternarna(ll l,ll d){//nepotrebno

    if(d-l<=7){
        ll res=LLONG_MAX;
        for(ll i=l;i<=d;i++)res=min(res,(ll)provera(i));
        return res;

    }

    ll prva=(l+l+d)/3;
    ll druga=(l+d+d)/3;
    if(provera(prva)<provera(druga))return ternarna(l,druga);
    else if(provera(prva)>provera(druga))return ternarna(prva,d);
    return ternarna(prva,druga);

}


int main()
{
    scanf("%lld %lld", &n, &m);//PROMENI SVE U LL
    for(ll i=1;i<=n;i++){
        scanf("%lld",niz+i);
    }
    sort(niz+1,niz+n+1,greater<ll>());
    //for(ll i=1;i<=n;i++)printf("%lld\n",niz[i]);

    ll prosli=m;
    for(ll i=1;i<=n;i++){
        for(ll j=niz[i]+1;j<=prosli;j++){
            svipre[j]=i-1;
        }
        prosli=niz[i];
    }
    for(ll i=1;i<=prosli;i++)svipre[i]=n;
    prosli=0;
    for(ll i=m;i>=1;i--){
        for(ll j=prosli+1;j<=niz[i];j++){
            sviposle[j]=n-i;
        }
        prosli=niz[i];
    }
    for(ll i=prosli+1;i<=m;i++)sviposle[i]=n;

    //for(ll i=1;i<=n;i++)printf("  %lld %lld\n",i,provera(i));

    ll gde=0,res=provera(0);
    for(ll i=m;i>=0;i--){
        while(gde<n && niz[gde+1]>=i)
            gde++;
        //printf(" %lld %lld\n",i,gde);
        res=min(res,provera(gde));
    }
    printf("%lld",res);
    return 0;
}