#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);
	vector<ll> b = a;
	set<pair<ll, ll>> st;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		st.insert({ a[i], i });
	}
	b = a;
	ll all = 0;

	for (int _ = 0; _ < k; _++) {
		ll ind = 0;
		ind = (*(--st.end())).second;
		all += a[ind] + 1;
		a[ind] = -1;
		st.erase({ --st.end() });
	}
	ll res = 0;
	vector<ll> left;
	for (int i = 0; i < n; i++) {
		if (a[i] != -1) {
			left.push_back(i);
		}
	}
	vector<ll> pref(left.size());
	vector<ll> suf(left.size());
	pref[0] = a[left[0]] + 1;
	for (int i = 1; i < left.size(); i++) {
		pref[i] = max(pref[i - 1], a[left[i]] + (i + 1));
	}
	suf[left.size() - 1] = a[left[left.size() - 1]] + left.size();
	for (int i = left.size() - 2; i >= 0; i--) {
		suf[i] = max(suf[i + 1], a[left[i]] + (i + 1));
	}
	for (int i = 0; i < n; i++) {
		if (a[i] == -1) {
			a[i] = b[i];
			auto p = lower_bound(left.begin(), left.end(), i);
			if (p == left.end()) {
				res = max(res, all - (a[i] + 1) + max(ll(a[i] + 1 + left.size()), ll(pref.back())));
			}
			else {
				ll ind = p - left.begin();
				ind--;
				ll tmp = all - (a[i] + 1);
				if (ind == -1) {
					tmp += max(a[i] + 1, suf[0] + 1);
				}
				else {
					ll first = pref[ind];
					ll second = a[i] + 1 + ind + 1;
					ll third = suf[ind + 1] + 1;
					tmp += max(max(first, second), third);

				}
				res = max(res, tmp);
			}





			a[i] = -1;
		}
	}
	cout << res;
}
int main()
{
	solve();
}

