#include<bits/stdc++.h>
using namespace std;
long long arr[300010];
long long arr2[300010];
int main()
{

    long long a,b,c,d,e,i,j;
    cin >> a >> b;

    long long k=0,chk=0;
    for(i=0;i<a;i++)
    {
        cin >> d;
        arr[d]++;
        chk=max(d,chk);
        k=max(arr[d],k);

    }
    for(i=0;i<=chk;i++){
            if(i==0)
       arr2[i]=min(arr[i],b);
      else{
        arr2[i]=min(arr[i],arr2[i-1]);
      }
      if(arr2[i]==0)
        break;

    }
    long long past=0,sum=0;
    for(i=chk;i>=0;i--){
            long long present=arr2[i];
            sum=sum+(present-past)*(i+1);
            past=present;


    }
    cout << sum << endl;


}

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<complex>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
#define removeduplicates(vec) vec.erase( unique( vec.begin(), vec.end() ), vec.end() )
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void solve(){
	ll n,k;
	cin>>n>>k;
	int a[n];
	int mp[n+1]={0};
	int maxi=0;
	rep(i,n){
		cin>>a[i];
		mp[a[i]]++;
		maxi=max(maxi,a[i]);
	}
	ll ans=0;
	mp[maxi+1]=0;
	for(ll x=0;x<=n;x++){
		ll f=mp[x];
		ll can=min(f,k);
		ans+=(k-can)*x;
		k=can;
	}
	cout<<ans;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}