#include <iostream>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <math.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

static const int inf = 1e15;
static const ld eps = 1e-7;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n + 1);
    vector<pair<int, int>> s;
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        s.push_back({a[i], i});
    }
    sort(all(s));
    int kmin = 0;
    int maxx = -1;
    int maxxi = -1;
    vector<int> ind(n + 1);
    vector<bool> can(n + 1);
    vector<int> full(n + 1);
    vector<int> sv(n + 1);
    for (int i = n; i >= 1; i--) {
        full[i] = a[i] + 1;
        if (a[i] > maxx) {
            can[i] = false;
            maxx = a[i];
            maxxi = i;
        } else {
            can[i] = true;
            sv[i] = maxxi;
        }
    }
    int b = n - k;
    for (int i = 0; i < n - k; i++) {
        if (can[s[i].second]) {
            full[sv[s[i].second]]++;
            full[s[i].second] = 0;
        } else if (b != n + 1) {
            if (can[s[b].second]) {
                if (-full[s[b].second] + 1 > -full[s[i].second]) {
                    full[s[b].second] = 0;
                    full[sv[s[b].second]]++;
                    b++;
                } else {
                    full[s[i].second] = 0;
                }
            } else {
                if (-full[s[b].second] < -full[s[i].second]) {
                    full[sv[s[b].second]]++;
                    b++;
                } else {
                    full[s[i].second] = 0;
                }
            }
        } else {
            full[s[i].second] = 0;
        }
    }
    int ans = 0;
    for (auto &c : full) {
        ans += c;
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int tt = 1;
    // cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}
