#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (auto &x : a) cin >> x;
    vector<vector<ll>> dp(n + 1, vector<ll>(k + 1));
    for (int s = 1; s <= k; ++s) {
        for (int i = 1; i <= n; ++i) {
            for (int t = 0; t < i; ++t) {
                dp[i][s] = max(dp[i][s], a[i - 1] + dp[t][s - 1] + i - t);
            }
        }
    }
    cout << dp[n][k] << '\n';
}
