#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ld long double
#define test ll t=0;cin>>t; while(t--)
#define loop(i,a,b) for(i=a;i<=b;i++)
#define loopr(i,a,b) for(i=a;i>=b;i--)
#define lb lower_bound
#define ub upper_bound
#define mid(l,r) mid=l+(r-l)/2
#define endl "\n"
#define yess cout<<"YES\n"
#define noo cout<<"NO\n"


int main()
{
   #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   #endif
   fastio;
   ll n,k;cin>>n>>k;
   vector<ll>a(n);
   ll i,y=0;
   ll s[1000000]={0};
   ll ans=0;
   for(i=0;i<n;i++)
   {
    cin>>a[i];
    s[a[i]]++;
   }
   for(i=0;i<1e6;)
   {
    if(s[i]==0){
      ans=ans+i;y++;
      if(y==k)break;
     if(i==0)break;
      i=0;continue;

    }
    s[i]--;i++;
   }
   cout<<ans;
    
}

#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<algorithm>
#define int long long int
using namespace std;

signed main(){
    int n, k, temp;
    cin >> n >> k;
    vector<int> arr(n);
    for(int i=0;i<n;i++) cin >> arr[i];
    sort(arr.begin(), arr.end());
    vector<int> count(arr[arr.size()-1]+2);
    for(int i : arr) count[i]++;
    int ans = 0;
    int current = min(k, count[0]);
    for(int i=1;i<count.size();i++){
        if(count[i] < current){
            ans = ans + i*(current-count[i]);
            current = count[i];
        }
    }
    cout << ans << endl;
}