#ifdef _DEBUG
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cassert>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define int int64_t

void solve() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int& x : a) cin >> x;
	int ans = 0;
	for (int i = 0; i < k - 1; ++i) ans += a[i] + 1;
	int mx = 0;
	for (int i = k - 1, cnt = 1; i < n; ++i, ++cnt) mx = max(mx, a[i] + cnt);
	cout << ans + mx << endl;
	return;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int test = 1;
	//cin >> test;

	while (test--) {
		solve();
	}

	return 0;
}