//I wrote this code 4 u <3
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll inf = 1e18;

signed main(int32_t argc, char* argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto& x : a) {
        cin >> x;
    }
    ll ans = -inf;
    vector<vector<ll>> t(k);
    vector<vector<vector<ll>>> kek;
    auto Dfs = [&](auto&& self, int u) {
        if (u == n) {
            bool ok = 1;
            ll nw = 0;
            for (auto &x : t) {
                ok &= !x.empty();
                ll cur = -inf;
                for (int i = 0; i < (int) x.size(); ++i) {
                    cur = max(cur, x[i] + i + 1);
                }
                nw += cur;
            }
            if (ok) {
                if (ans < nw) {
                    ans = nw;
                }
            }
            return;
        }
        for (int i = 0; i < k; ++i) {
            t[i].push_back(a[u]);
            self(self, u + 1);
            t[i].pop_back();
        }
    };
    Dfs(Dfs, 0);
    cout << ans << '\n';
}

/*

*/