
#include <iostream>
#include <limits>
#include <chrono>
#include <random>
#include <iomanip>
#include <algorithm>
#include <chrono>
#include <random>
#include <math.h>
#include <set>
using namespace std;
#define int long long
void check(vector <int>& vec, int n, int k) {
	int sum = 0;
	multiset <pair<int, int>> st;
	for (int i = 0;i < n - 1;i++)st.insert({ vec[i],i });
	while (st.size() > k) {
		st.erase(st.begin());
	}
	int max_pos = 0;
	while (st.size()) {
		sum += st.begin()->first;
		max_pos = max(max_pos, st.begin()->second);
		st.erase(st.begin());
	}
	if (max_pos == n - 1) {
		cout << sum + n;
		exit(0);
	}
}
signed main()
{
	int n, k;
	cin >> n >> k;
	vector <int> vec(n);
	int sum = 0;
	for (int i = 0;i < n;i++)cin >> vec[i];
	multiset <int> st;
	int val = 0;
	for (int i = 0;i < k - 1;i++) {
		st.insert(vec[i]);
		val += vec[i];
	}
	sum = val + k + vec[k - 1];
	for (int max_r = k - 1;max_r < n - 1;max_r++) {
		val += vec[max_r];
		st.insert(vec[max_r]);
		val -= *st.begin();
		st.erase(st.begin());
		sum = max(val + max_r + 2 + vec[max_r + 1],sum);
		
	}
	cout << sum;
}
