#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+50;
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        s=s*10+ch-'0';
        ch=getchar();
    }
    return s*f;
}
int u[N],n,k,a[N];
int main(){
   cin>>n>>k;
    for(int i=1;i<=n;i++)
    {a[i]=read();u[a[i]]++;}
    int ans=0;
for(int j=1;j<=k;j++)
{
    for(int i=0;i<=n;i++)
    {
        if(!u[i]){ans+=i;break;}
        u[i]--;
    }
}
    cout<<ans;
}
#include<bits/stdc++.h>

#define ll long long int
#define ld long double
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9+10
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;




ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

//cout<< fixed << setprecision(10)
//__builtin_popcountll();
//|_2.4_|=2  

int main(){
    
    fast;
    int n,k,i,j;
    cin>>n>>k;
    int f[n+10]={0};
    for(i=0;i<n;i++)
    {
        int x;
        cin>>x;
        f[x]++;
    }
    int ans=0;
    i=0;
    while(k!=0)
    {
        if(f[i]>=k)
        {
            i++;
            continue;
        }
        else
        {
            ans=ans+(k-f[i])*i;
            k=f[i];
            i++;
        }


    }
    cout<<ans;

    
}
    


    
    
