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

using ll = long long;

const ll INF = 2e18;

int main() {
    int n, k;
    cin >> n >> k;

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

    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 <= k; j++) {
            ll mx = 0;
            for (int i1 = i; i1 > 0; i1--) {
                mx = max(mx + 1, a[i1 - 1] + 1);
                dp[i][j] = max(dp[i][j], dp[i1 - 1][j - 1] + mx);
            }
        }
    }

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