#pragma GCC optimize("trapv")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

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

using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pr = pair<ll, ll>;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 1;
const ll INFLL = 1e18 + 1;
int reps = 1;

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

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

template<typename T>
inline void print(const vector<T> &a, string sep=" ") {
    for (auto &x : a) cout << x << sep;
    cout << "\n";
}

template<typename T>
inline void print(const multiset<T> &a, string sep=" ") {
    for (auto &x : a) cout << x << sep;
    cout << "\n";
}

//====================================

void solve() {
    ll n, k; cin >> n >> k;
    vector<ll> a(n);
    for (auto &x : a) cin >> x;
    ll ans = 0;
    multiset<ll> cur;
    int mxi = k-1; 
    ll cs = 0;
    for (int i = 0; i < k; i++) {
        cur.insert(a[i]);
        cs += a[i];
    }
    ans = cs + k;
    for (int i = k; i < n; i++) {
        ll cval = cs + mxi + 1;
        ll nval = cs - *cur.begin() + a[i] + i + 1;
        if (nval > cval) {
            cs -= *cur.begin();
            cs += a[i];
            mxi = i;
            cur.erase(cur.begin());
            cur.insert(a[i]);
            ans = max(ans, nval);
        }
    }
    cout << ans << "\n";
}

//====================================

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL 
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    cin >> reps;
#endif
    for (int i = 0; i < reps; i++) {
#ifdef LOCAL 
        cout << "Test case #" << i + 1 << " ==============\n";
#endif
        solve();
#ifdef LOCAL 
        cout << "End test ==============\n";
#endif
    }
    return 0;
}

// g++ -std=c++23 -Wall -Wextra -Wshadow -DLOCAL -D_GLIBCXX_DEBUG -fsanitize=address,undefined -O2 A.cpp -o A
