#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<stack>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>

using namespace std;
using ll = long long int;
using ld = long double;

int n, k;
vector<int> a;
vector<vector<int>> cnt;
int kol = 0;
ll mx = 0;

void rec(int ind) {
    if (ind == n) {
        if (kol > 0) return;
        ll su = 0;
        for (int i = 0; i < k; ++i) {
            int mx1 = 0;
            for (int j = 0; j < (int)cnt[i].size(); ++j) {
                mx1 = max(mx1, cnt[i][j] + j + 1);
            }
            su += mx1;
        }
        mx = max(mx, su);
        return;
    }
    for (int i = 0; i < k; ++i) {
        cnt[i].push_back(a[ind]);
        bool t = false;
        if (cnt[i].size() == 1) {
            kol--;
            t = true;
        }
        rec(ind + 1);
        cnt[i].pop_back();
        if (t) {
            kol++;
        }
    }
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt = 1;
    while (tt--) {
        solve();
    }
}