#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <iomanip>
using namespace std;
using ll = long long;
using ld = long double;
#define endl '\n'
vector<int> f;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k; cin >> n >> k; vector<int> v(n);
	for (auto& i : v) cin >> i;
	vector<pair<int, int>> v1(n);
	for (int i = 0; i < n; i++) v1[i] = { v[i], i };
	sort(v1.rbegin(), v1.rend());
	vector<int> ps;
	for (int i = 0; i < k; i++) ps.push_back(v1[i].second);
	sort(ps.begin(), ps.end()); int lst = ps.back();
	for (int i = lst + 1; i < n; i++) {
		if (v[lst] + lst < v[i] + i) {
			ps.pop_back(); ps.push_back(i); lst = i;
		}
	}
	ll res = lst + 1;
	for (int i = 0; i < ps.size(); i++) res += v[ps[i]];
	cout << res;
	return 0;
}
