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


#define all(x) x.begin(), x.end()
#define ll long long
#define vll vector<ll>


using namespace std;

vll suff_max, a;
ll n, k, ans = 0;

void recurs(ll i, vector<pair<ll, ll>> &curr) {
    if (i == n) {
        ll summ = 0;
        for (ll j = 0; j < curr.size(); j++) {
            if (curr[j].second == 0) return;
            summ += curr[j].first;
        }
        ans = max(ans, summ);
        return;
    }

    for (ll j = 0; j < k; j++) {
        pair<ll, ll> oldval = curr[j];
        curr[j].first = max(curr[j].first, a[i] + curr[j].second + 1);
        curr[j].second += 1;
        recurs(i + 1, curr);
        curr[j] = oldval;
    }
}

signed main() {
    // ll n, k;
    // cin >> n;
    cin >> n >> k;

    a.resize(n, 0);
    suff_max.resize(n, 0);

    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    suff_max[n - 1] = a[n - 1];
    for (ll i = n - 2; i >= 0; i--) {
        suff_max[i] = max(suff_max[i], suff_max[i + 1]);
    }

    vector<pair<ll, ll>> curr(k, {0, 0});
    //recurs(0, curr);

    /*for (ll i = 0; i < n; i++) {
        if (k == 0) break;
        ans += a[i] + 1;
        k--;
    }*/

    vector<vector<ll>> dp(n, vector<ll> (k + 1, 0));
    ll globalmax = a[0] + 1;
    for (ll i = 0; i < n; i++) {
        globalmax = max(globalmax, a[i] + i + 1);
        dp[i][1] = globalmax;
        for (ll j = 1; j <= min(i + 1, k); j++) {
            for (ll k = i - 1; k >= 0; k--) {
                ll maximum = a[i];

                for (ll u = k + 1; u <= i; u++) maximum = max(maximum, a[u] + u - k);
                dp[i][j] = max(dp[i][j], dp[k][j - 1] + maximum);
            }
        }
    }

    for (ll i = n - 1; i >= 0; i--) {
        ans = max(ans, dp[i][k]);
    }

    cout << ans << endl;
    // cout << n << endl;
}