/* � 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-x.second);
            boxmax = x.second;
        }
        lastfirst = x.first;
        i++;
    }
    // auto last = cnt.rbegin();
    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;
}

//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // 
#include <vector> //
#include <algorithm> // 
#include <queue> // 
#include <string> // 
#include <functional> // 
#include <set> // 
#include <map> // 
#include <random> // 
#include <ctime> // 
#include <bitset> // 
#include <cassert>

// #include <atcoder/all>
// using namespace atcoder;
// g++ t.cpp -o t -I .

#define DB cerr<<"D"<<endl

using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
using P=pair<ll,ll>;
const ll M = 998244353;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
ll mod_pow(ll x, ll a, ll m) { ll an = 1; while(a > 0) { if (a&1) an = an * x % m; x = x * x % m; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;} bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
ll gcd(ll a, ll b) {if (b==0) return a; else return gcd(b, a%b);}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};

int main() {
  ll n,k; cin>>n>>k;
  ll a[n]; for(int i=0;i<n;i++) cin>>a[i];
  ll b[n+1]={}; for(int i=0;i<n;i++) b[a[i]]++;
  ll an=0;
  for(int i=0;i<k;i++) {
    //for(int j=0;j<=n;j++)cout<<b[i]<<" ";cout<<endl;
    for(int j=0;j<=n;j++) {
      if (b[j]==0) {
        an+=j; break;
      } else {
        b[j]--;
      }
    }
    //cout<<an<<endl;
  }
  cout<<an<<endl;
}

// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest
