#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define endl '\n'
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,bmi2,fma")

int n, k, ans = 0, ans_now = 0, cnt0 = 0;
vector<int> arr, now, cnti, ansi;

void rec() {
    if (cnt0 > n - now.size()) {
        return;
    }
    if (now.size() == n) {
        ans = max(ans, ans_now);
        return;
    }
    for (int i = 0; i < k; ++i) {
        now.push_back(i);
        cnti[i]++;
        if (cnti[i] == 1) {
            cnt0--;
        }
        int p = ansi[i];
        ansi[i] = max(ansi[i], arr[(int)now.size() - 1] + cnti[i]);
        ans_now = ans_now - p + ansi[i];
        rec();
        ans_now = ans_now + p - ansi[i];
        ansi[i] = p;
        cnti[i]--;
        if (cnti[i] == 0) {
            cnt0++;
        }
        now.pop_back();
    }
}

signed main() {
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n >> k;
    cnt0 = k;
    arr.resize(n);
    cnti.resize(k);
    ansi.resize(k);
    for (auto& it : arr) {
        cin >> it;
    }
    rec();

    cout << ans << endl;
}

/*
5 3
3 7 10 1 2

24


*/