#include <bits/stdc++.h>

using namespace std;
#define int int64_t
#define endl '\n'

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int& i : a) cin >> i;

    //map<pair<int, vector<pair<int, int>>>, int> used;

    auto rec = [&](auto&& self, int i, vector<pair<int, int>> cnt) -> int {
        if (i == n) {
            int res = 0;
            bool ok = true;
            for (int i = 0; i < int(cnt.size()); ++i) {
                res += cnt[i].first;
                ok &= cnt[i].second >= 1;
            }
            return ok ? res : 0;
        }
        //if (used.find({i, cnt}) != used.end()) return used[{i, cnt}];
        int res = 0;
        for (int j = 0; j < int(cnt.size()); ++j) {
            int cur = a[i] + cnt[j].second + 1;
            auto prev = cnt[j];
            cnt[j] = make_pair(max(cnt[j].first, cur), cnt[j].second + 1);
            res = max(res, self(self, i + 1, cnt));
            cnt[j] = prev;
        }
        return res;
    };

    cout << rec(rec, 0, vector<pair<int, int>>(k));
    return;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int test = 1;
    //cin >> test;

    while (test--) {
        solve();
    }

    return 0;
}