#include <bits/stdc++.h>
// #include <bits/extc++.h>

using namespace std;

#define all(a)	a.begin(),a.end()
#define rall(a)	a.rbegin(),a.rend()
#define FastIO	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long			ll;
typedef long double			ld;
typedef unsigned long long	ull;
// typedef _int128_t lll;

template<typename T1, typename T2>
ostream& operator<< (ostream &x, const pair<T1, T2> &pr) { return x << "{" << pr.first << ", " << pr.second << "}"; }
template<typename T> void cerr_cont(const T &cont) { for (auto &it : cont) cerr << it << ' '; }
template<typename T> void print_cont(const T &cont, ostream &x=cout) { for (auto &it : cont) x << it << ' '; }

int t;
vector<int> maxes;
ll cur_sum = 0;

void add(int x) {
	for (int i = 0; i < t; ++i) {

		if (maxes[i] == -1) {
			cur_sum += x;
			maxes[i] = x;
			break;
		}

		if (maxes[i] < x) {
			cur_sum -= maxes[i];
			cur_sum += x;
		   	swap(x, maxes[i]);
		}
	}
}

ll get_sum() {
	return cur_sum;
}

int main() {
	FastIO;
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (auto &it : a) cin >> it;

	t = k - 1;
	maxes.resize(t, -1);

	for (int i = 0; i < t; ++i) add(a[i]);
	ll res = -1;
	for (int i = k - 1; i < n; ++i) {
		res = max(res, i + 1 + a[i] + get_sum());
		add(a[i]);
	}
	cout << res;
	return 0;
}

