#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long
#define sll __int128
#define size(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
//#define int long long

mt19937 rnd(time(0));

ll ans = 0;

void rec(int n, int st, int k, vector<int> &a, vector<vector<int>> &b){
    if (st == n){
        int cnt = 0;
        ll sm = 0;
        for (int i = 0; i < k; i++){
            if (!b[i].empty()){
                cnt++;
                int mx = 0;
                for (int j = 0; j < size(b[i]); j++){
                    mx = max(mx, a[b[i][j]] + j + 1);
                }
                sm += mx;
            }
        }
        if (cnt == k){
            ans = max(ans, sm);
        }
        return;
    }
    for (int i = 0; i < k; i++){
        b[i].push_back(st);
        rec(n, st + 1, k, a, b);
        b[i].pop_back();
    }
}

void solve(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto &x : a){
        cin >> x;
    }
    vector<vector<int>> b(k);
    rec(n, 0, k, a, b);
    cout << ans;
}

signed main(){
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int ttt = 1;
    //cin >> ttt;
    while (ttt--){
        solve();
    }
}
