#include <bits/stdc++.h>
using namespace std;
int main(){
int t = 1;
//cin >> t;
while(t--){
int n, k;
cin >> n >> k;
int a[n];
map<int,int>mp;
for(int i = 0 ; i < n ; i++){
scanf("%d",a+i);
mp[a[i]]++;
}
if(!mp[0]){
cout<<0<<endl;
continue;
}
int ind, mx = 0;
for(int i = 0 ; i <= n + 1 ; i++){
mx = max(mp[i], mx);
if(!mp[i]){
ind = i;
break;
}
}
long long ans = 0;
while(k){
int sum = 0;
for(int j = 0 ; n >= k && j <= ind && mp[j]; j++){
sum++;
mp[j]--;
n--;
}
k--;
ans += sum;
}
cout<<ans<<endl;
}
}
Copy