#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <chrono>
using namespace std;
using ll = long long;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

pair<ll, ll> f(ll n, ll k, vector<ll>& a, ll c) {
    set<pair<ll, ll>> s;
    s.insert({a[0] + 1, 1});
    ll ans = a[0] + 1;
    for (int i = 1; i < n; ++i) {
        auto p = *s.begin();
        ll mx = max(p.first, p.second + 1 + a[i]);
        if (mx - p.first > c + a[i] + 1) {
            ans -= p.first;
            s.erase(s.begin());
            s.insert({mx, p.second + 1});
            ans += mx;
        }
        else {
            ans += a[i] + 1;
            s.insert({a[i] + 1, 1});
        }
    }
    return {(int)s.size(), ans};
}

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif;
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    ll l = -1e17, r = 2e18;
    while (r - l > 1) {
        ll m = (l + r) / 2;
        if (f(n, k, a, m).first > k)
            r = m;
        else
            l = m;
    }
    cout << f(n, k, a, l).second;
}