#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;

#define int long long

const int N = 1e5 + 10;

int a[N];
int ans = -INFi;

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

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

    vector<vector<int>> mn(n, vector<int>(n));
    for (int i = 0; i < n; ++i) {
        int m = INF;
        for (int j = i; j < n; ++j) {
            m = min(m, a[j] + j);
            mn[i][j] = m;
        }
    }


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

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

signed 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;
}