#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define str string
#define pb push_back
#define ins insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pii pair<int, int>
#define ff first
#define ss second
#define ld long double
#define sz(a) (int)a.size()
#define int ll

mt19937 rnd(1488);

void solve(){
    int n, k;
    cin >> n >> k;
    vector<pii> c(n);
    for (int i = 0; i < n; i++){
        cin >> c[i].ff;
        c[i].ff += i + 1;
        c[i].ss = n - i;
    }
    sort(rall(c));
    vector<pii> c2(k);
    for (int i = 0; i < k; i++){
        c2[i].ff = c[i].ss;
        c2[i].ss = n - c[i].ff;
    }
    sort(all(c2));
    int ans = 0;
    int pr = -1;
    for (int i = 0; i < k; i++){
        ans += c2[i].ss - pr - 1;
        pr = c2[i].ff;
    }
    cout << ans;
}

int32_t main(){
    cin.tie(0)->ios_base::sync_with_stdio(0);
#ifdef LOCAL
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif // LOCAL
    int _ = 1;
    //cin >> _;
    while (_--){
        solve();
    }
}
