#include "bits/extc++.h"

using namespace std;
using namespace __gnu_pbds;

using ll = long long;

template<typename T>
istream &operator>>(istream &is, vector<T> &a);

template<typename T>
ostream &operator<<(ostream &os, vector<T> &a);


using ordered_set = tree<int, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    cin >> a;

    vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, -1e18));
    dp[0][0] = 0;
    for (int r = 0; r < n; ++r) {
        for (int l = 0; l <= r; ++l) {
            for (int kold = 0; kold < k; ++kold) {
                dp[r + 1][kold + 1] = max(
                        dp[r + 1][kold + 1],
                        dp[l][kold] + (a[r] + (r - l) + 1)
                );
            }

        }
    }

    ll ans = 0;
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= k; ++j) {
            ans=max(ans,dp[i][j]);
        }
    }
    cout << ans;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &v: a) is >> v;
    return is;
}

template<typename T>
ostream &operator<<(ostream &os, vector<T> &a) {
    for (auto v: a) os << v << " ";
    return (os << "\n");
}
