#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define mem(x, y) memset(x, y, sizeof x)
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define int ll

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int n, k;
	cin >> n >> k;
	
	vector <int> a(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	
	multiset <int> s;
	int sum = 0;
	
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i >= k) ans = max(ans, i + a[i] + sum);
		
		s.insert(a[i]);
		sum += a[i];
		while (sz(s) >= k) {
			sum -= *s.begin();
			s.erase(s.begin());
		}
	}
	cout << ans;
	
	return 0;
}

/*
5 2
3 7 10 1 2
*/
