#include <bits/stdc++.h>
using ll = long long;
using namespace std;

void solve() {
    int n, k; cin >> n >> k;
    vector <int> a(n, 0);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector <vector <ll>> dp(n, vector <ll>(n + 1, -1));
    for (int i = 0; i < n; i++) {
        dp[i][1] = (ll) (i + 1) + a[i];
    }
    for (int cur_k = 2; cur_k <= n; cur_k++) {
        for (int i = 0; i < n; i++) {
            for (int j = i - 1; j > -1; j--) {
                if (dp[j][cur_k - 1] == -1) continue;
                dp[i][cur_k] = max(dp[i][cur_k], dp[j][cur_k - 1] + (i - j) + a[i]);
            }
        }
    }
    ll ans = -1;
    for (int i = 0; i < n; i++) {
        ans = max(ans, dp[i][k]);
    }
    cout << ans << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int test = 1;
    for (int i = 0; i < test; i++) {
        solve();
    }
}
