#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second

typedef long long ll;
typedef pair<int,int> ii;

const int N = 3e5;
const int INF = 1e9;
int n, k;
int st[4*N], lz[4*N];

void prop(int idx, int l, int r) {
    if (lz[idx] == 0) return;
    st[idx] += lz[idx];
    if (l < r) {
        lz[2*idx] += lz[idx];
        lz[2*idx+1] += lz[idx];
    }
    lz[idx] = 0;
}

void update(int idx, int l, int r, int x, int y, int val) {
    prop(idx,l,r);
    if (l > y || r < x) return;
    if (l >= x && r <= y) {
        lz[idx] += val;
        prop(idx,l,r);
        return;
    }
    int m = (l+r)/2;
    update(2*idx,l,m,x,y,val); update(2*idx+1,m+1,r,x,y,val);
    st[idx] = min(st[2*idx],st[2*idx+1]);
}

int minOf(int idx, int l, int r, int x, int y) {
    prop(idx,l,r);
    if (l > y || r < x) return INF;
    if (l >= x && r <= y) return st[idx];
    int m = (l+r)/2;
    return min(minOf(2*idx,l,m,x,y),minOf(2*idx+1,m+1,r,x,y));
}

int binser(int l, int r) {
    if (minOf(1,0,n,l,r) > 0) return r+1;
    if (l == r) return l;
    int m = (l+r)/2;
    if (l <= m && minOf(1,0,n,l,m) == 0) return binser(l,m);
    return binser(m+1,r);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        int a; cin >> a;
        update(1,0,n,a,a,1);
    }
    ll ans = 0;
    while (k--) {
        int mex = binser(0,n);
        if (mex == 0) break;
        // cout << ">> " << mex << '\n';
        ans += mex;
        update(1,0,n,0,mex-1,-1);
    }
    cout << ans << '\n';
    return 0;
}
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define FOR(i, a, b) for(ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(ll i = (ll)(a - 1); i >= (ll)(b); i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,K;
    cin >> N >> K;
    vl A(N);
    vl cnt(300001);
    rep(i,N){
        cin >> A[i];
        cnt[A[i]]++;
    }
    ll ans=0;
    ll now=K;
    rep(i,300001){
        chmin(now,cnt[i]);
        ans+=now;
    }
    cout << ans << endl;
}