#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define vi vector<ll>
#define vii vector<vi>
#define vip vector<pair<ll, ll>>
#define viip vector<vip>
#define endl '\n'
#define pb push_back
#define all(a) a.begin(), a.end()

void solve() {
    ll n, k;
    cin >> n >> k;
    vi a(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    vii dp(n + 1, vi(k + 1));
    dp[0][0] = 0;
    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
        for (ll j = 1; j <= min(i, k); j++) {
            for (ll u = 0; u < i; u++) {
                dp[i][j] = max(dp[i][j], dp[u][j-1] + a[i-1] + i - u);
                ans= max(ans, dp[i][j]);
            }
        }
    }
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}
