#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define int long long

using namespace std;
using namespace __gnu_pbds;
using ll = long long;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int n, k;
vector<int> a;

struct seg_tree {
    vector<pair<int, int>> d = vector<pair<int, int>>(4 * n);

    void build(int u, int lx, int rx) {
        if (rx - lx == 1) {
            d[u] = {a[lx], lx};
            return;
        }
        int mx = (rx + lx) / 2;
        build(u * 2 + 1, lx, mx);
        build(u * 2 + 2, mx, rx);
        d[u] = max(d[u * 2 + 1], d[u * 2 + 2]);
    }

    void set(int u, int i, int lx, int rx) {
        if (rx - lx == 1) {
            d[u] = {-1e9, 0};
            return;
        }
        int mx = (rx + lx) / 2;
        if (i < mx)
            set(u * 2 + 1, i, lx, mx);
        else
            set(u * 2 + 2, i, mx, rx);
        d[u] = max(d[u * 2 + 1], d[u * 2 + 2]);
    }

    pair<int, int> get(int u, int l, int r, int lx, int rx) {
        if (r <= lx or rx <= l)
            return {-1e9, 0};
        if (l <= lx and rx <= r)
            return d[u];
        int mx = (rx + lx) / 2;
        return max(get(u * 2 + 1, l, r, lx, mx), get(u * 2 + 2, l, r, mx, rx));
    }
};

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> k;
    a.resize(n);
    for (auto &x: a) cin >> x;
    int res = 0, mx = -1;
    seg_tree dd;
    dd.build(0, 0, n);
    for (int i = 0; i < n; i++)
        a[i] += i;
    seg_tree ddd;
    ddd.build(0, 0, n);
    for (int i = 0; i < k; i++) {
        auto q1 = dd.get(0, 0, mx, 0, n);
        auto q2 = ddd.get(0, mx, n, 0, n);
        if (q1.first < q2.first - mx) {
            ddd.set(0, q2.second, 0, n);
            dd.set(0, q2.second, 0, n);
            res += q2.first - mx;
            mx = q2.second;
        } else {
            ddd.set(0, q1.second, 0, n);
            dd.set(0, q1.second, 0, n);
            res += q1.first;
        }
    }
    cout << res << '\n';
    return 0;
}
