#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

//#pragma GCC optimize("Ofast, unroll-loops, fast-math, no-stack-protector, inline")
//#pragma GCC target("avx, avx2")

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define int long long

const ll INF = 1e18 + 228;

random_device rd;
mt19937 rnd(rd() + 228 + 57 - 179);

ll ans = -INF;

void rec(vector<int> &a, vector<vector<int>> &mn, int n, int k, int pos) {
    if (pos == n) {
        ll cur = 0;
        for (auto i : mn) {
            if (i.empty()) return;
            ll mx = -INF;
            for (int j = 0; j < i.size(); ++j) {
                mx = max(mx, i[j] + j + 1);
            }
            cur += mx;
        }
        ans = max(ans, cur);
        return;
    }
    for (int i = 0; i < k; ++i) {
        mn[i].push_back(a[pos]);
        rec(a, mn, n, k, pos + 1);
        mn[i].pop_back();
    }
}

void solve() {
    int n, k;
    cin >> n >> k;
    vector<vector<int>> mn(k);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    rec(a, mn, n, k, 0);
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int tt = 1;
    //cin >> tt;
    while (tt--) solve();
    return 0;
}
