#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define forn(a,b,c) for(int a=b;a<=c;a++)
#define ford(a,b,c) for(int a=b;a>=c;a--)
const int N=1e5+5;
int n,m,curr,a[N],first[N];ll res=LLONG_MAX,ans;
//do neke tacke levo,posle desno
int bs(int x){
    int lo=0,hi=n;
    while(lo<hi){
        int mid=(hi+lo+1)/2;
        if(a[mid]<x)
            lo=mid;
        else
            hi=mid-1;
    }
    return lo;
}
int main()
{
    scanf("%d%d",&n,&m);
    forn(i,1,n){
        scanf("%d",&a[i]);
    }
    sort(a+1,a+n+1);
  //  printf("%d\n",ans);
    forn(i,1,m){
        first[i]=bs(i);
        //printf("first[%d]:%d\n",i,first[i]);
    }
    forn(last,0,n){
        ans=0;
        forn(i,1,m){
            int cnt=abs(last-first[i]);
            ans+=(ll)cnt*(ll)(n-cnt);
        }
        res=min(res,ans);
        //printf("last:%d ans:%lld\n",last,ans);
    }
    printf("%lld\n",res);
    return 0;
}