#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

vector<ll> a;

bool cmp(int const &i, int const &j) {
    return a[i] < a[j];
}

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

    vector<ll> kostyl(n);
    for (int i = 0; i < k; ++i) kostyl[i] = 1;
    for (int i = k; i < n; ++i) kostyl[i] = i - k + 2;
    multiset<ll> z;
    for (int i = 0; i < k; ++i) z.insert(a[i] + kostyl[i]);
    ll res = 0;
    for (int i = k; i < n; ++i) res = max(res, a[i] + kostyl[i]);
    if (res > *z.begin()) {
        z.erase(z.begin());
        z.insert(res);
    }
    res = 0;
    for (ll const &e : z) res += e;
    cout << res;
}

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

    solve();
}