#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#define ll long long

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll answer1 = 0;
    for (ll i1 = 0; i1 < (1 << n); i1++) {
        vector<ll> a1;
        vector<ll> a2;
        ll x = i1;
        for (ll i = 0; i < n; i++) {
            if (x % 2 == 0) {
                a1.push_back(a[i]);
            } else {
                a2.push_back(a[i]);
            }
            x = x / 2;
        }
        if (a1.size() == 0 && a2.size() != k) {
            continue;
        }
        if (1 + a2.size() != k) {
            continue;
        }
        ll answer2 = 0;
        for (auto elem : a2) {
            answer2 += elem + 1;
        }
        ll max1 = 0;
        for (ll i = 0; i < a1.size(); i++) {
            max1 = max(max1, a1[i] + i + 1);
        }
        answer2 += max1;
        answer1 = max(answer1, answer2);
    }
    cout << answer1 << '\n';
}