#include <bits/stdc++.h>

#ifndef LOCAL
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

const int mod = 10;

struct Modular {
    int x;

    Modular(int x = 0): x(x) {}

    friend Modular operator+(Modular a, Modular b) {
        int res = a.x + b.x;
        return res - (res >= mod ? mod : 0);
    }

    friend Modular operator-(Modular a, Modular b) {
        int res = a.x - b.x;
        return res + (res < 0 ? mod : 0);
    }

    friend Modular operator*(Modular a, Modular b) {
        return ll(a.x) * b.x % mod;
    }
};

const int maxn = 10;
ll a[maxn];
ll dp[maxn + 1];
ll cnt[maxn + 1];
int n;

pair<ll, ll> calc(ll L) {
    cnt[0] = 0;
    dp[0] = 0;
    vector<int> st;
    ll mx = 0;
    ll cntmx = 0;
    vector<pair<ll, ll>> mxs;
    for (int i = 1; i <= n; ++i) {
        pair<ll, ll> res = {0, 0};
        while(!st.empty() && a[st.back()] < a[i - 1]) {
            res = max(res, mxs.back());
            mxs.pop_back();
            st.pop_back();
        }
        if(!st.empty()) {
            int ind = st.back() + 1;
            res = max(res, make_pair(dp[ind] - ind, cnt[ind]));
        }
        res.first += a[i - 1];
        if (res.first > mx || (res.first == mx && res.second > cntmx)) {
            mx = res.first;
            cntmx = res.second;
        }
        dp[i] = mx + L;
        cnt[i] = cntmx + 1;
        st.push_back(i - 1);
        res.first -= a[i - 1];
        mxs.push_back(max(res, make_pair(dp[i] - i, cnt[i])));
        // if (mx < dp[i] - i + a[i - 1] || (dp[i] - i + a[i - 1] == mx && cntmx < cnt[i])) {
        //     mx = dp[i] - i + a[i - 1];
        //     cntmx = cnt[i];
        // }
    }
    return {dp[n], cnt[n]};
}

void solve() {
    int k;
    cin >> n >> k;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i] += i + 1;
    }
    ll l = -1e15;
    ll r = 1e15;
    while (r - l > 1) {
        ll mid = (l + r) / 2;
        auto res = calc(mid);
        if (res.second < k) {
            l = mid;
        } else {
            r = mid;
        }
    }
    auto ans = calc(r);
    cout << ans.first - r * k;
}

signed main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#else
    freopen("C:\\Users\\User\\aboab\\input.txt", "r", stdin);
#endif
    solve();
}