#include <bits/stdc++.h>
using namespace std;
#define int long long
int ans = 0;
void rec(vector<vector<int>> &d, const vector<int> &a, int &j, const int &n){
    if (j == n){
        int c = 0;
        for (int i = 0; i < (int)d.size(); ++i){
            int nw = 0;
            for (int j = 0; j < (int)d[i].size(); ++j){
                nw = max(nw, d[i][j] + j + 1);
            }
            c += nw;
        }
        ans = max(ans, c);
        return;
    }
    for (int i = 0; i < (int)d.size(); ++i){
        d[i].push_back(a[j]);
        ++j;
        rec(d, a, j, n);
        --j;
        d[i].pop_back();
    }
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    for (int &i : a){
        cin >> i;
    }
    vector<vector<int>> lol(k);
    int j = 0;
    rec(lol, a, j, n);
    cout << ans << "\n";
}
