//#pragma GCC optimize("O3");
//#pragma GCC target("avx, avx2")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define ALL(X) (X.begin()), (X.end())
#define sz(X) (int)(X.size())

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned int ui;

#define ordered_set tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
   	vector<int> a(n);
   	for (int i = 0; i < n; ++i) {
   		cin >> a[i];
   	}
    ordered_set s;
    int t = 0;
    ll sum = 0;
    ll ans = 0;
    for (int i = 0; i < k - 1; ++i) {
    	s.insert({a[i], t++});
    	sum += a[i];
    }
    for (int i = k - 1; i < n; ++i) {
    	ans = max(ans, a[i] + sum + i - k + 1);
    	auto c1 = *s.find_by_order(i - k + 1);
    	s.insert({a[i], t++});
    	auto c2 = *s.find_by_order(i - k + 2);
    	//cout << c1.first << " " << c2.first << "\n";
    	if (c1 != c2) {
    		sum -= c1.first;
    		sum += a[i];
    	}
    }
    cout << ans + k << '\n';
    return 0;
}
