    #include<bits/stdc++.h>
    using namespace std;

    #define ll long long
    #define pb push_back
    #define printV(v) for(int i=0;i<(int)v.size();i++){cout << v[i]<< " ";} cout << endl
    #define printRev(v) for(int i=(int)v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
    #define sortV(v) sort(v.begin(),v.end())
    #define revV(v) reverse(v.begin(),v.end())


    ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,p,q,y;
    string str = "", s1 = "", s2 = "";
    ll mod = 1e9 + 7;
    //ll mod = 998244353;
    const int N = 100009;

   

   
    /**
        2021 challenge (16/365) : 16.01.2021
    */
    
    
  

    void solve(){
        cin >> n >> k;
        vector<ll> freq(n+100,0);
        for(int i=0; i < n; i++){
            cin >> a;
            freq[a]++;
        }
        int active = k;
        int curr = 0;
        ll sum = 0;
        for(int i=0; i <= n; i++){
            if(active == 0) break;
            if(freq[i] < active){
                int diff = active - freq[i];
                sum += (diff * i);
                active = freq[i];
            }
        }
        cout << sum << endl;
    }

    int main(){
        ios_base::sync_with_stdio(false);
        
        
        
        int cases = 1;
        //cin >> cases;


        while(cases--) solve();
        return 0;
    }
#include <bits/stdc++.h>
#define int long long
#define sc(x) scanf("%lld",&x);

#define P pair<int,int>
#define fi first
#define se second
#define pb push_back
#define endl '\n'

using namespace std;
int N;
int A[300006];
int B[300005];

signed main()
{
    int n,k;
    sc(n)sc(k)
    int x;
    for(int i = 0; i < n; i++){
        sc(x)
        A[x]++;
    }
    int ans = 0,r;
    for(int i = 0; i < n; i++){
        if(A[i] >= k){
            continue;
        }else{
           r = k - A[i];
           ans += r*i;
           k -= r;
        }
        if(k == 0)break;
    }
    cout << ans << '\n';
    return 0;
}
