#include <bits/stdc++.h>
#ifndef  WILEYNE
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#endif
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using ordered_set = __gnu_pbds::tree<int, __gnu_pbds::null_type,std::less<int>,__gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;





using ll = long long;
using ld = long double;

using namespace std;

const int MAX_N = (int)2e5;
const double eps = acos(-1);
const int INT_INF = (int)2e9+10;
const int MOD = (int)1e9+7;
auto seet = chrono::high_resolution_clock ::now().time_since_epoch().count();
mt19937 rng(seet);


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef WILEYNE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
   ll n,k;
    cin>>n>>k;
    vector<ll>v(n);
    for(auto &c:v) cin>>c;
    ll ans = 0;
    set<ll>st;
    ll cur_sums = 0;
    for(int i  =0;i<k;++i){
        st.insert(v[i]);
        cur_sums+=v[i];
    }
    ans = cur_sums+k;
    for(int i = k;i<n;++i){
        auto it = st.begin();
        cur_sums-=*it;
        //st.erase(it);
        cur_sums+=v[i];
        ans = max(ans,cur_sums+i+1);
        if(*it>v[i]){
            st.erase(it);
            st.insert(v[i]);
        }
        else{
            cur_sums-=v[i];
            cur_sums+=*it;
        }
    }
    cout<<ans;
    return 0;
}
