    /* Goal to be a Master */
    #include <algorithm>
    #include <bits/stdc++.h>
    #include <cstring>
    #include <climits>
    #include <cstdlib>
    #include <cstdio>
    #include <bitset>
    #include <vector>
    #include <cmath>
    #include <ctime>
    #include <queue>
    #include <stack>
    #include <map>
    #include <set>
    #include<tuple>
    using namespace std;
    #define endl "\n"
    #define fo1(i,n) for(int i=1;i<=n;i++)
    #define min3(a,b,c) min(a,min(b,c))
    #define s(v) (ll)v.size()
    #define e(v) v.empty()
    #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define vi vector<int>
    #define fi first
    #define se second
    #define db double
    #define U unsigned
    #define P pair<int,int>
    #define ll long long
    #define vll vector<ll>
    #define pll pair<ll,ll>
    #define pb push_back
    #define eb emplace_back 
    #define mp make_pair
    #define all(x) x.begin(),x.end()
    #define CLR(i,a) memset(i,a,sizeof(i))
    #define fo(i,a,b) for(int i = a;i <= b;++i)
    #define ro(i,a,b) for(int i = a;i >= b;--i) 
    #define ppll pair < pll , pll > 
    #define sd(x) scanf("%d",&x) 
    #define sld(x) scanf("%lld",&x) 
    #define INF 1e18 
    #define eps 0.00001 
    #define le length 
    #define debug(n1) cout << n1 << "\n" 
    int gcd(int a,int b)
    {
      if(b==0)
        return a;
      else
      return gcd(b,a%b);
    }
    int binex(int base,int pow)
    {
      int res=1;
      while(pow){
      if(pow%2)
      { res*=base;pow--;}
      else
      {base*=base;pow=pow/2;}
      }
      return res;
    }
    void sieve(int a[],int N)
    {
      for(int i=1;i<=N;i++)
        a[i]=1;
      a[1]=0;
      for(int i= 2;i*i<=N;i++)
      {
        if(a[i])
        {
        for(int j=i*i;j<=N;j+=i)
          a[j]=0;
      }
      }
    }
    string CONVERT_TO_BINARY(int s) { 
        string res = ""; 
        while(s != 0) { 
            res += (char)('0' + s % 2); 
            s /= 2; 
        } 
        reverse(res.begin() , res.end()); 
        return res; 
    } 
    int STOI(string s) { 
        int num = 0; 
        int po = 1; 
        for(int i=s.length()-1;i>=0;i--) 
        { 
            num += po * (s[i] - '0'); 
            po *= 10; 
        } 
        return num; 
    } 
    int main()
    {
        IOS
        int n,k;
        cin>>n>>k;
        int a[n];
        int m[n+1]={0};
        int h=0;
        for(int i=0;i<n;i++)
        {
          cin>>a[i];h=max(h,a[i]);
          m[a[i]]++;
        }
        ll ans=0;
        if(m[0]<k)
         {
             int diff=k-m[0];
            k-=diff;
         }
        for(int i=1;i<h;i++)
        {

            if(m[i]<k)
            {
                int diff=k-m[i];
              ans+=i*diff;
              k-=diff;
            }
        }
        
        if(m[h]<k)
        {
            int diff=k-m[h];
           ans+=h*diff;
           k-=diff;
           ans+=(h+1)*m[h];
         } 
        else
        {
            ans+=(h+1)*k;
        } 
        cout<<ans;
        cout.precision(8); 
        cout << fixed; 
        return 0;
    }
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD int(1e9+7)
#define INF int(1e9)
#define LINF ll(1e18)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<ll,ll>

int n,k;
int a[310000];

int main(){
  cin>>n>>k;
  rep(i,n){
    int val; cin>>val;
    a[val]++;
  }
  int ans=0;
  rep(i,n){
    if(a[i]<k){
      ans += a[i];
      k=a[i];
    }else{
      ans += k;
    }
  }
  cout<<ans<<endl;
}