#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define vi vector<ll>
#define vii vector<vi>
#define viii vector<vii>
#define vip vector<pair<ll, ll>>
#define viip vector<vip>
#define endl '\n'
#define pb push_back
#define all(a) a.begin(), a.end()

void solve() {
    ll n, k;
    cin >> n >> k;
    vi a(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    viii dp(n + 1, vii(k + 1, vi(2)));
    dp[0][0][0] = 0;
    dp[0][0][1] = 0;
    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
        for (ll j = 1; j <= min(i, k); j++) {
            dp[i][j][1] = max(dp[i - 1][j - 1][1], dp[i - 1][j][0]) + a[i - 1] + 1;
            dp[i][j][0] = max(dp[i - 1][j][0], dp[i - 1][j - 1][1]) + 1;
            ans = max(ans, dp[i][j][0]);
            ans = max(ans, dp[i][j][1]);
           // cout << i << " " << j << " " << dp[i][j][0] << " " << dp[i][j][1] << endl;
        }
        for (ll j = 1; j <= k; j++) {
            dp[i][j][1] = max(dp[i][j-1][1], dp[i][j][1]);
            dp[i][j][0] = max(dp[i][j-1][0], dp[i][j][0]);
        }
    }
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}
