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

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define endl "\n"
#define ff first
#define ss second
#define ordered_set tree<int, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>
#define all(x) x.begin(), x.end()

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

    int n, k;
    cin >> n >> k;

    vector<int> a(n, 0);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    multiset<int> st;
    int csm = 0;

    int ans = 0;

    for (int i = 0; i < n; i++) {
        if (i < k - 1) {
            st.insert(a[i]);
            csm += a[i];
            continue;
        }
        ans = max(ans, i + csm + a[i] + 1);
        if (a[i] > *(st.begin())) {
            csm -= *(st.begin());
            csm += a[i];
            st.erase(st.begin());
            st.insert(a[i]);
        }
    }

    cout << ans << endl;

}
