#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <deque>
#include <iomanip>
using namespace std;
using ll = long long;
void solve() {
	ll n;
	cin >> n;
	ll k;
	cin >> k;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll all = 0;
	for (int _ = 0; _ < k - 1; _++) {
		ll maxi = 0;
		ll ind = -1;
		for (int i = 0; i < n; i++) {
			if (maxi <= a[i]) {
				maxi = a[i];
				ind = i;
			}
		}
		a[ind] = -1;
		all += (maxi + 1);
	}
	vector<ll> left;
	for (int i = 0; i < n; i++) {
		if (a[i] != -1) {
			left.push_back(a[i]);
		}
	}
	ll mx = 0;
	for (int i = 0; i < left.size(); i++) {
		mx = max(mx, left[i] + i + 1);
	}
	cout << mx + all;
}
int main()
{
	solve();
}

