#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <random>
#include <unordered_map>

using namespace std;

using ll = long long;

#pragma GCC optimaze("Ofast");

ll ans = 0;

void rec(vector<ll>& a, vector<int>& b, int i, int k) {
	int n = int(a.size());
	if (i == n) {
		vector<ll> ma(k), sz(k);
		for (int I = 0; I < n; I++) {
			sz[b[I]]++;
			ma[b[I]] = max(ma[b[I]], sz[b[I]] + a[I]);
		}
		ll su = 0;
		for (ll x : ma) su += x;
		ans = max(ans, su);
		return;
	}
	for (int x = 0; x < k; x++) {
		b.push_back(x);
		rec(a, b, i + 1, k);
		b.pop_back();
	}
}

ll foo1(ll n, ll k, vector<ll> a) {
	vector<int> b;
	ans = 0;
	rec(a, b, 0, k);
	return ans;
}

ll foo2(ll n, ll k, vector<ll> a) {
	ll su = 0;
	for (int i = n - 1; i >= n - k; i--) su += a[i];
	return su + n;
}

int main() {
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	unordered_map<ll, ll> ma;
	for (int i = 0; i < n; i++) ma[a[i]]++;
	sort(a.begin(), a.end());
	vector<ll> c;
	c.push_back(a[0] + ma[a[0]]);
	for (int i = 1; i < n; i++) {
		if (a[i] == a[i - 1]) c.push_back(a[i]);
		else c.push_back(a[i] + ma[a[i]]);
	}
	sort(c.begin(), c.end());
	ll su = 0;
	for (int i = n - 1; i >= n - k; i--) {
		su += c[i];
	}
	cout << su;
}



