#include <iostream>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include<deque>
#include<queue>
#include<algorithm>


using namespace std;
using ll = long long;
ll gt(ll l, ll r, vector<vector<ll>> &best) {
	ll t = log2(r - l + 1);
	return max(best[l][t], best[r - (1ll << t) + 1][t]);
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);

	ll n, k; cin >> n >> k;
	vector<ll>a(n);
	ll sz = log2(n) + 1;

	vector<vector<ll>> best(n + 1, vector<ll>(sz));
	vector<pair<ll, ll>> ind;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		a[i] += (i + 1);
		ind.push_back({ a[i], i });
	}
	sort(ind.rbegin(), ind.rend());
	vector<ll>index;
	for (int i = 0; i < min(n, k); ++i) {
		index.push_back(ind[i].second);
	}
	sort(index.begin(), index.end());
	ll  d = 0;
	ll ans = 0;
	for (int i = 0; i < index.size(); ++i) {
		ans += a[index[i]] - d;
		d = max(d, (index[i] + 1));
	}
	cout << ans << '\n';
}
