#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];
		});
	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) {
		if (p[i] != right) {
			ans += a[p[i]] + 1;
		}
	}
	int cnt = 1;
	for (int i = 0; i < n; ++i) {
		if (!ban[i] && i <= right) {
			++cnt;
		}
	}
	int cur = a[right] + cnt;
	for (int i = 0; i < n; ++i) {
		if (i > right) {
			++cnt;
			cur = max(cur, a[i] + cnt);
		}
	}
	cout << ans + cur << "\n";
	return 0;
}