#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    cin.sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    ll cnt[n];
    memset(cnt,0,sizeof(cnt));
    ll i,j;
    for(i=0;i<n;i++) {
        ll x;
        cin>>x;
        cnt[x]+=1;
    }
    ll boxes[k];
    memset(boxes,-1,sizeof(boxes));
    i=0;
    j=0;
    while(i<n) {
        ll flag=0;
        while(cnt[i]>0) {
            if(boxes[j]+1==i || boxes[j]==i) {
                boxes[j]=i;
                j=(j+1)%k;
                cnt[i]-=1;
            }
            else {
                j=0;
                if(boxes[j]+1==i || boxes[j]==i) {
                    boxes[j]=i;
                    j=(j+1)%k;
                    cnt[i]-=1;
                }
                else {
                    flag=1;
                    break;
                }
            }
        }
        i+=1;
        j=0;
        if(flag==1)
            break;
    }
    ll ans=0;
    for(i=0;i<k;i++)
    ans=ans+boxes[i]+1;
    cout<<ans;
}

#include<bits/stdc++.h>
#define N 300005
#define ll long long
#define rep(i, l, r) for(int i=l; i<=r; ++i)
#define per(i, r, l) for(int i=r; i>=l; --i)
using namespace std;
int n, k;
int a[N], c[N];
int main(){
	scanf("%d%d", &n, &k);
	rep(i, 1, n){
		scanf("%d", &a[i]);
		++c[a[i]];
	}
	c[0]=min(c[0], k);
	int ans=c[0];
	rep(i, 1, n){
		c[i]=min(c[i], c[i-1]);
		ans+=c[i];
	}
	printf("%d", ans);
	return 0;
}