/* � Ashiq Uddin Pranto
Department of Computer Science and Engineering
BATCH 27
University Of Rajshahi,Bangladesh
*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define FOR(x,y) for(ll i=x;i<=y;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define matrix(x) vector<vector<x>>
#define vss vector<string>
#define PI (2*acos(0.0))
#define sqr(x) ((x)*(x))
#define sf(a) scanf("%d",&a)
#define sfl(a) scanf("%lld",&a)
#define sff(a,b) scanf("%d %d",&a,&b)
#define sffl(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define ms(a,b) memset(a, b, sizeof(a))
#define ff first
#define ss second
#define lcm(a, b) ((a)*((b)/__gcd(a,b)))
#define all(a) a.begin(),a.end()
#define readfile freopen("input.txt","r",stdin);
#define writefile freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define gap " "
#define mx 104
#define inf (ll)1e9
#define WHITE 1
#define GRAY 2
#define BLACK 3
#define EMPTY_VALUE -1
#define mod 1000000007
#define MOD(a,b) (a%b + b)%b
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
void eff()
{
ll n,k;
sffl(n,k);
vll a(n);
map<ll,ll>cnt;
for(ll i=0;i<n;i++)
{
sfl(a[i]);
cnt[a[i]]++;
}
// debug(cnt);
ll boxmax;
auto x = cnt.begin();
if(x->first==0)
{
boxmax = min(k,x->second);
}
else
{
printf("0\n");
return;
}
ll i=0;
ll ans = 0;
ll lastfirst = 0;
for(auto x: cnt)
{
if(abs(lastfirst-x.first)>=2)
{
ans+=i*(boxmax);
cout<<ans<<endl;
return;
}
if(x.second <boxmax)
{
ans+=i*(boxmax-1);
// ans+=i;
boxmax = x.second;
}
lastfirst = x.first;
i++;
}
ans+=i*(boxmax);
cout<<ans<<endl;
}
int main()
{
// fastio
// ll test ;
// sfl(test);
// for(ll i=0;i<test;i++)
// {
// printf("Case %lld: ",i+1);
eff();
// }
// cout<<check(81);
return 0;
}
Lyog77+9IEFzaGlxIFVkZGluIFByYW50bwogICBEZXBhcnRtZW50IG9mIENvbXB1dGVyIFNjaWVuY2UgYW5kIEVuZ2luZWVyaW5nCiAgIEJBVENIIDI3CiAgIFVuaXZlcnNpdHkgT2YgUmFqc2hhaGksQmFuZ2xhZGVzaAoqLwojaW5jbHVkZTxiaXRzL3N0ZGMrKy5oPgogCiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgbGQgbG9uZyBkb3VibGUKI2RlZmluZSBGT1IoeCx5KSBmb3IobGwgaT14O2k8PXk7aSsrKQojZGVmaW5lIHBiKHgpIHB1c2hfYmFjayh4KQojZGVmaW5lIG1wIG1ha2VfcGFpcgojZGVmaW5lIHBpaSBwYWlyPGludCxpbnQ+CiNkZWZpbmUgcGxsIHBhaXI8b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bGwgbGFzdGZpcnN0ID0gMDsKICAgIGZvcihhdXRvIHg6IGNudCkKICAgIHsKICAgICAgICBpZihhYnMobGFzdGZpcnN0LXguZmlyc3QpPj0yKQogICAgICAgIHsKICAgICAgICAgICAgYW5zKz1pKihib3htYXgpOwogICAgICAgICAgICBjb3V0PDxhbnM8PGVuZGw7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgICAgaWYoeC5zZWNvbmQgPGJveG1heCkKICAgICAgICB7CiAgICAgICAgICAgIGFucys9aSooYm94bWF4LTEpOwogICAgICAgICAgICAvLyBhbnMrPWk7CiAgICAgICAgICAgIGJveG1heCA9IHguc2Vjb25kOwogICAgICAgIH0KICAgICAgICBsYXN0Zmlyc3QgPSB4LmZpcnN0OwogICAgICAgIGkrKzsKICAgIH0KICAgIGFucys9aSooYm94bWF4KTsKICAgIGNvdXQ8PGFuczw8ZW5kbDsKICAgIAp9CiAKaW50IG1haW4oKQp7CiAgICAvLyBmYXN0aW8KICAgIC8vIGxsIHRlc3QgOwogICAgLy8gc2ZsKHRlc3QpOwogICAgLy8gZm9yKGxsIGk9MDtpPHRlc3Q7aSsrKQogICAgLy8gewogICAgICAgIC8vIHByaW50ZigiQ2FzZSAlbGxkOiAiLGkrMSk7CiAgICAgICAgZWZmKCk7CiAgICAvLyB9Ci8vICAgIGNvdXQ8PGNoZWNrKDgxKTsKICAgIHJldHVybiAwOwp9Cg==