#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
#define all(x) x.begin(), a.end()
void fst(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

const int maxn = 2e5;

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    fst();
    int n;cin >> n;
    int k;cin >> k;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    vector<int> sub(n);
    if(k == n){
        int cur = 0;
        for(int i= 0; i < n; ++i){
            cur += a[i]+1;
        }
        cout << cur; return 0;
    }
    int ans = 0;
    int ind = -1;
    int it = 0;
    while(it != k-1){
        ans += a[it]+1;
        ++it;
    }
    int cur = 0;
    for(int i = it; i < n; ++i){
        cur = max(cur, a[i] + i - it + 1);
    }

    cout << ans+cur;


}