#include<bits/stdc++.h>

using namespace std;

using ll = long long;

ll ans = 0;

ll calc(vector<vector<int>> &st) {
    ll res = 0;
    for (int i = 0; i < st.size(); ++i) {
        int mx = 0;
        for (int j = 0; j < st[i].size(); ++j) {
            mx = max(mx, st[i][j] + j + 1);
        }
        res += mx;
    }
    return res;
}

void rec(vector<vector<int>> st, vector<int> &a, int last) {
    if (last == a.size()) {
        ans = max(ans, calc(st));
        return;
    }
    for (int i = 0; i < st.size(); ++i) {
        if (i != 0 && st[i - 1].size() == 0) break;
        st[i].push_back(a[last]);
        rec(st, a, last + 1);
        st[i].pop_back();
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<vector<int>> st(k);
    rec(st, a, 0);
    cout << ans;
}

