#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
//constexpr long long MOD = 1000000007;
constexpr long long MOD = 998244353;
constexpr long long INF = 1000000000 + 100;
constexpr long long LINF = 1000000000000000000 + 100;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    ll n, k; cin >> n >> k;
    vector<ll> C(n);
    rep(i, n){
        ll a; cin >> a; C[a]++;
    }
    vector<ll> box(k); ll last = k;
    rep(i, n){
        last = min(last, C[i]);
        rep(j, last)box[j] = i+1;
    }
    ll res = accumulate(all(box), 0LL);
    cout << res << ln;
}   
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 1e6+10;
map<ll,ll> mp;
ll a[maxn],f[maxn];
int main(){
	ll n,k;
	cin >> n >> k;
	ll cnt = 1;
	ll res=0,st=0;
	for(ll i=1;i<=n;i++){
		ll k;
		cin>>k;
		if(f[k]==0){
			a[cnt++] =k;
			f[k] =1;
		}
		mp[k]++;
	}
	sort(a+1,a+cnt);
	while(mp[0]){
		ll i=0;
		while(1){
			if(mp[i]!=0){
				mp[i]--;
			}
			else{
				res+=i;
				st++;
				break;
			}
			i++;
		}
		if(st == k) break;
	}
	cout << res;
	return 0;
}