#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll =long long;
using vi = vector<ll>;
using vc = vector<char>;
using vs = vector<string>;
using P = pair<ll , ll>;
using vp = vector<P>;
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define rep2(i, s, n) for (int i = (s); i < n; i++)
#define sort(A) sort(A.begin(),A.end());
#define reverse(A) reverse(A.begin(),A.end());
#define vecint2(A, n, m) vector<vector<long long int>> A(n, vector<long long int>(m));
#define vecchar2(A, n, m) vector<vector<char>> A(n, vector<char>(m));
#define k(s) cout << fixed << setprecision(s);
#define t cout<<"OK"<<endl;
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
const long double pi=3.14159265358979323846;

int main() {
  int N,K;
  cin>>N>>K;
  vi A(300005);
  rep(i,300005) A[i]=0;
  rep(i,N){
    int a;
    cin>>a;
    A[a]++;
  }
  int nokori=K;
  ll ans=0;
  int ks=0;
  while(nokori>0){
    if(A[ks]>=nokori){
      ks++;
    }else{
      ans=ans+ks;
  //    cout<<ks<<endl;
      nokori--;
    }
  }
  cout<<ans<<endl;
}
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> cnt(n, 0);
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        ++cnt[x];
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        k = min(k, cnt[i]);
        ans += k;
    }
    cout << ans << "\n";
    return 0;
}
