#include <bits/extc++.h>

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = k - 1; i < n; i++) {
        int cur = 0;
        {
            int z = a[i] + 1;
            for (int j = i + 1; j < n; j++) {
                z = max(z, a[j] + (j - i) + 1);
            }
            cur = z;
        }
        if (i > 0) {
            cur += a[i - 1] + (i - (k - 2));
            vector<int> b;
            for (int j = 0; j < i - 1; j++) {
                b.push_back(a[j]);
            }
            sort(b.rbegin(), b.rend());
            for (int j = 0; j < k - 2; j++) {
                cur += b[j] + 1;
            }
        }
        ans = max(ans, cur);
        //cerr << "!! " << i + 1 << "  " << cur << '\n';
    }
    cout << ans << '\n';
    return 0;
}
/*

5 3
3 7 10 1 2

 */