//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
#include <numeric>
#include <algorithm>
#include <random>
using ll = long long;
#define int ll
#define all(a) a.begin(), a.end()

using namespace std;
//using namespace __gnu_pbds;

//using odered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rnd(0);

void solve() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = 0;
	int s = 0;
	set<pair<int, int>> st;
	for (int i = 0; i < k - 1; i++) {
		st.insert({ a[i],i });
		s += a[i];
	}
	ans += s + a[k - 1] + k;
	for (int i = k; i < n; i++) {
		if (a[i-1] > st.begin()->first) {
			s -= st.begin()->first;
			st.erase(st.begin());
			s += a[i-1];
			st.insert({ a[i - 1], i });
		}
		ans = max(ans, s + a[i]  +i + 1);
	}
	cout << ans;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef LOCAL
	auto f1 = freopen("input.txt", "r", stdin);
	auto f2 = freopen("output.txt", "w", stdout);
#endif

	solve();
}