#include <bits/stdc++.h>

using namespace std;
using ll = long long;
int n, k;
vector<vector<int>> a;
vector<int> s;

ll rec(int i) {
    if (i == n) {
        ll res = 0;
        if (a.size() < k) return -1;
        for (const auto &vc: a) {
            int tmp = 0;
            for (int m = 0; m < vc.size(); m++) {
                tmp = max(tmp, m + s[vc[m]] + 1);
            }
            res += tmp;
        }
        return res;
    }


    ll res = 0;
    for (int x = 0; x < a.size(); x++) {
        a[x].push_back(i);
        res = max(res, rec(i + 1));
        a[x].pop_back();
    }
    if (a.size() < k) {
        a.push_back({i});
        res = max(rec(i + 1), res);
        a.pop_back();
    }
    return res;
}

void solve() {
    cin >> n >> k;
    s.resize(n);
    for (int i = 0; i < n; ++i) cin >> s[i];
    cout << rec(0);
}

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