#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <set>
#include <unordered_set>

using namespace std;

using ll = long long;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	ll n, k; cin >> n >> k;
	vector<ll> vec(n);
	for (int i = 0; i < n; i++) cin >> vec[i];
	ll ans = 0;
	for (int i = k - 1; i < n; i++) {
		vector<ll> prev;
		for (int j = 0; j < i; j++) prev.push_back(vec[j]);
		sort(prev.rbegin(), prev.rend());
		ll lans = vec[i] + i + 1;
		for (int j = 0; j < k - 1; j++) lans += prev[j];
		ans = max(ans, lans);
	}
	cout << ans << endl;
}