#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, k;
	cin >> n >> k;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll all = 0;
	for (int i = 0; i < k - 1; i++) {
		all += (a[i] + 1);
	}
	ll mx = 0;
	for (int i = k - 1; i < n; i++) {
		mx = max(mx, a[i] + (i - (k - 1)) + 1);
	}
	cout << all + mx;
}
int main()
{
	solve();
}

