#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 ld = long double;

ll res(vector<ll> a, ll k) {
    ll n = a.size();
    ll ans = 0;
    vector<ll> vans;
    if (k == 1){
        ll mask = (1 << n)-1;
        ll val = 0;
        vector<ll> neww;
        for (ll i = 0;i<n;i++) {
            if (mask & (1 << i)){
                val = max((ll) val,(ll) a[i] + i + 1 - (ll) 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 (ll mask = 1; mask < (1 << n);mask++) {
        if (__builtin_popcount(mask) > n-k+1) {
            continue;
        }
        ll val = 0;
        vector<ll> neww;
        for (ll i = 0;i<n;i++) {
            if (mask & (1 << i)){
                val = max((ll) val,(ll) a[i] + i + 1 - (ll) 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() {
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0;i<n;i++) {
        cin >> a[i];
    }
    cout << res(a,k);

}

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

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