#define LOCAL
//#define SUKA
#ifdef SUKA
#pragma GCC optimize("O3")
#define GCC optimize("unroll-loops")
#endif
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << x << "\n";
#else
#define debug(x)
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using lll = __int128;
using ld = long double;

ll res(vector<int> a, int k) {
    int n = a.size();
    int ans = 0;
    vector<int> vans;
    if (k == 1){
        int mask = (1 << n)-1;
        int val = 0;
        vector<int> neww;
        for (int i = 0;i<n;i++) {
            if (mask & (1 << i)){
                val = max((int) val,(int) a[i] + i + 1 - (int) neww.size());
            }
            else{
                neww.push_back(a[i]);
            }
        }
        auto tp = res(neww, k-1);
        if (ans < val + tp){
            ans = val + tp;
            vans = neww;
        }
        return ans;
    }
    for (int mask = 1; mask < (1 << n);mask++) {
        if (__builtin_popcount(mask) > n-k+1) {
            continue;
        }
        int val = 0;
        vector<int> neww;
        for (int i = 0;i<n;i++) {
            if (mask & (1 << i)){
                val = max((int) val,(int) a[i] + i + 1 - (int) neww.size());
            }
            else{
                neww.push_back(a[i]);
            }
        }
        auto tp = res(neww, k-1);
        if (ans < val + tp){
            ans = val + tp;
            vans = neww;
        }
    }
    return ans;
}

void solve() {
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0;i<n;i++) {
        cin >> a[i];
    }
    cout << res(a,k);

}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
        cout << "\n";
    }
    //cout << res({1,2,3},1);
}
