#include <bits/stdc++.h>

using ll = long long;

using namespace std;

void solve() {
    ll n, k;
    cin >> n >> k;
    vector<ll> A(n);
    for (ll i = 0; i < n; i++) {
        cin >> A[i];
    }
    vector<ll> M(k - 1);
    for (ll i = 0; i < k - 1; i++) {
        M[i] = A[i];
    }
    sort(M.rbegin(), M.rend());
    ll ans = 0;
    for (ll i = k - 1; i < n; i++) {
        ll d = i + 1 + A[i];
        for (ll j = 0; j < k - 1; j++) {
            d += M[j];
        }
        ans = max(ans, d);
        M.push_back(A[i]);
        sort(M.rbegin(), M.rend());
    }
    cout << ans << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t = 1;
    //cin >> t;
    for (ll i = 0; i < t; i++) {
        solve();
    }
    return 0;
}
