#pragma GCC optimize("Ofast")

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

typedef long long ll;

#define len(x) (int)x.size()
#define all(x) x.begoin(), x.end()
const ll INF = 1e18;
const int INFi = 1e9;

const int N = 5e5 + 10;

ll a[N];

void solve() {
    int n, k;
    cin >> n >> k;

    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }

    vector<vector<ll>> mn(n+1, vector<ll>(n+1));
    for (int i = 1; i <= n; ++i) {
        ll m = -INF;
        for (int j = i; j <= n; ++j) {
            m = max(m, a[j] + j);
            mn[i][j] = m;
        }
    }

    vector<vector<ll>> dp(n+1, vector<ll>(k+1, -INF));
    dp[0][0] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= min(i,k); ++j) {
            for (int x = 1; x <= i; ++x) {
                dp[i][j] = max(dp[i][j], dp[x-1][j-1] + mn[x][i] - x + 1);
            }
        }
    }

    cout << dp[n][k] << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt","w", stdout);
#endif

    int t = 1;
//    cin >> t;
    while(t--) {
        solve();
    }

    return 0;
}