#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <ctime>
#include <map>
#include <fstream>
#include <unordered_map>
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define x first
#define y second
#define int int64_t
using namespace std;
typedef pair<int, int> pt;

const int mod = 1e9 + 7;

int32_t main() {
	int n;
	cin >> n;
	int k;
	cin >> k;
	vector<int> a(n);
	vector<int> cnt(n + 1);
	for (int& e : a) {
		cin >> e;
		cnt[e]++;
	}
	int ans = 0;
	for (int j = 0; j < k; ++j) {
		for (int i = 0; i <= n; ++i) {
			if (cnt[i] == 0) {
				ans += i;
				break;
			}
			cnt[i]--;
		}
	}
	cout << ans;

	
}

#include <bits/stdc++.h>
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define REPS(i, ss, nn ) for(int i = ss ; i < (int) nn; i++)
#define REV(i, ss, nn ) for(int i = ss ; i >= nn; i--)
#define deb(x) std::cout << #x << " " << x << endl;
#define debl(x) std::cout << #x << " " << x << " ";
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
namespace std{
    template<class Fun>
    class y_combinator_result{
        Fun fun_;
        public:
            template<class T>
            explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)){}
            template<class ...Args>
            decltype(auto) operator()(Args&&...args){
                return fun_(std::ref(*this), std::forward<Args>(args)...);
            }
    };
    template<class Fun>
    decltype(auto) y_combinator(Fun && fun){
        return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
    }
};
template<typename T>
bool u_max(T& a, T b){
    if( a < b){
        a = b;
        return true;
    }
    return false;
}
template<typename T>
bool u_min(T& a, T b){
    if( a > b){
        a = b;
        return true;
    }
    return false;
}
struct edge{
    int to, from;
    ll cost;
    edge(){ edge(0,0);}
    edge(int to_, ll cost_){ edge(to_, -1, cost_);}
    edge(int to_, int from_, ll cost_) : to(to_), from(from_), cost(cost_){}
};

template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}

void solve(){
    int n , k;
    read(n, k);
    map<int,int> mp;
    REP(i, n){
        int a;
        cin >> a;
        mp[a]++;
    }

    ll ans = 0;
    for(int i = 0 ; i < k ; i++){
        if(mp[0] == 0){
            break;
        }
        REP(j,n){
            // deb(j)
            if(mp.find(j) == mp.end()){
                // cout << "No j ?" << endl;
                ans += j;
                break;
            }
            // deb(mp[j])
            if(mp[j] == 0){
                ans += j;
                break;
            }else{
                mp[j]--;
            }
        }
    }
    cout << ans << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}

