#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll infll = 1e18;

template<typename T>
istream& operator>>(istream& is, vector<T>& a) {
	for (auto& i : a) {
		is >> i;
	}
	return is;
}

mt19937 rng(228);

int32_t main() {
#ifdef LOCAL
	assert(freopen("C:\\Users\\User\\input.txt", "r", stdin));
#else
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
#endif
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	cin >> a;
	vector<int> p(n);
	iota(p.begin(), p.end(), 0);
	sort(p.begin(), p.end(), [&](int i, int j) {
		if (a[i] == a[j]) {
			return i > j;
		}
		return a[i] > a[j];
		});
	ll ANS = 0;
	{
		int right = 0;
		vector<bool> ban(n);
		for (int i = 0; i < k; ++i) {
			right = max(right, p[i]);
			ban[p[i]] = true;
		}
		ll ans = 0;
		for (int i = 0; i < k; ++i) {
			ans += a[p[i]] + 1;
		}
		for (int i = 0; i < n; ++i) {
			if (!ban[i] && i < right) {
				++ans;
			}
		}
		ANS = max(ANS, ans);
	}
	{
		ll ans = 0;
		vector<bool> ban(n);
		for (int i = 0; i < k - 1; ++i) {
			ans += a[p[i]] + 1;
			ban[p[i]] = true;
		}
		int cnt = 0;
		int mx = 0;
		for (int i = 0; i < n; ++i) {
			if (!ban[i]) {
				++cnt;
				mx = max(mx, a[i] + cnt);
			}
		}
		ANS = max(ANS, ans + mx);
	}
	cout << ANS << "\n";
	return 0;
}