#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
#define all(a) a.begin(), a.end()

int main() {
    ll n, k;
    cin >> n >> k;
    assert(n <= 15);
    vector<ll> a(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
    }
    ll ans = 0;
    for (ll mask = 0; mask < (1ll << n); ++mask) if (__builtin_popcount(mask) == k){
        if (((mask >> (n - 1)) & 1) == 0)
            continue;
        ll cnt = 1;
        ll mx = 0;
        ll res = 0;
        for (ll i = 0; i < n; ++i) {
            mx = max(mx, cnt + a[i]);
            ++cnt;
            if ((mask >> i) & 1ll) {
                res += mx;
                mx = 0;
                cnt = 1;
            }
        }
        ans = max(ans, res);
    }
    cout << ans;
}

