#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);
	set<pair<ll, pair<ll, ll>>> st;
	vector<pair<ll, pair<ll,ll>>> ind(n);

	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		a[i] +=1;
		ind[i] = { a[i], {i,i} };

		st.insert({ a[i], {i,i} });
	}
	ll gg = n;
	while (gg != k) {
		auto p = *st.begin();
		ll num = p.first;
		ll l = p.second.first;
		ll r = p.second.second;

		if (p.second.second != n - 1) {
			auto joy = ind[r + 1];
			ll was = joy.second.first;

			auto it = st.find(joy);
			st.erase(it);
			joy.second.first = l;
			joy.first += (r - l + 1);

			ind[l] = joy;
			ind[r] = joy;

			ind[joy.second.second] = joy;
			ind[was] = joy;
			st.insert(joy);
		} else {
			auto joy = ind[l - 1];
			ll w = joy.second.first, h = joy.second.second;
			st.erase(joy);
			joy.first = max(joy.first, num + (h - w + 1));
			joy.second.second = r;
			ind[joy.second.first] = joy;
			ind[joy.second.second] = joy;
			st.insert(joy);
		}
		st.erase(st.begin());
		gg--;
	}

	ll ans = 0;
	for (auto it = st.begin(); it != st.end(); it++) {
		ans += (it->first);
	}
	cout << ans << '\n';
}

