#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
mt19937 rnd1(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937 rnd(100);

ll rand(ll l, ll r) {
    return l + (rnd() % (r - l + 1));
}

const ll mod = 1'000'000'007;

namespace comba {
    vector<ll> fact;

    ll gcd(ll a, ll b) {
        if (a < b)
            swap(a, b);

        if (!b)
            return a;

        return gcd(b, a % b);
    }

    ll po(ll a, ll b) {
        if (!b)
            return 1;

        ll x = po(a, b / 2);
        x = (x * x) % mod;
        if (b & 1)
            x = (x * a) % mod;

        return x;
    }

    ll obr(ll x) {
        return po(x, mod - 2);
    }

    ll fac(ll x) {
        if (x <= 0)
            return 1;

        while (fact.size() < x + 1)
            fact.emplace_back((fact.back() * fact.size()) % mod);

        return fact[x];
    }

    ll C(ll k, ll n) {
        if (k > n)
            return 0;

        return ((fac(n) * obr(fac(k)) % mod) * obr(fac(n - k))) % mod;
    }
}

namespace dd {
    struct Node {
        Node *L, *R;
        ll c, y, v;

        Node(ll _v) {
            L = R = nullptr;
            c = 1;
            y = rnd();
            v = _v;
        }
    };

    ll sz(Node *r) {
        return r ? r->c : 0;
    }

    void update(Node *r) {
        r->c = sz(r->L) + 1 + sz(r->R);
    }

    pair<Node *, Node *> split(Node *r, ll k) {
        if (!r)
            return {nullptr, nullptr};

        if (sz(r->L) >= k) {
            auto p = split(r->L, k);
            r->L = p.second;
            update(r);
            return {p.first, r};
        }

        auto p = split(r->R, k - sz(r->L) - 1);
        r->R = p.first;
        update(r);
        return {r, p.second};
    }

    Node *merge(Node *r1, Node *r2) {
        if (!r1)
            return r2;

        if (!r2)
            return r1;

        if (r1->y > r2->y) {
            r1->R = merge(r1->R, r2);
            update(r1);
            return r1;
        }

        r2->L = merge(r1, r2->L);
        update(r2);
        return r2;
    }

    ll get(Node *r, ll ind) {
        auto pl = split(r, ind);
        auto pr = split(pl.second, 1);
        ll ans = pr.first->v;
        r = merge(merge(pl.first, pl.second), pr.second);
        return ans;
    }

    void insert(Node *r, ll val) {
        auto p = split(r, val);
        r = merge(merge(p.first, new Node(val)), p.second);
    }

    void cut(Node *r, ll L, ll R) {
        auto pl = split(r, L);
        auto pr = split(pl.second, R - L);
        r = merge(pl.first, pr.second);
    }
}

namespace geo {
    struct dot {
        ld x, y;

        dot(const ld _x, const ld _y) {
            x = _x, y = _y;
        }
    };

    ld scal(const dot &d1, const dot &d2) {
        return d1.x * d2.x + d1.y * d2.y;
    }

    ld vect(const dot &d1, const dot &d2) {
        return d1.x * d2.y - d1.y * d2.x;
    }

    dot ab(const dot &d1, const dot &d2) {
        return {d2.x - d1.x, d2.y - d1.y};
    }

    bool cmp(const dot &d1, const dot &d2) {
        return d1.x < d2.x || d1.x == d2.x && d1.y > d2.y;
    }

    vector<dot> obol(vector<dot> arr) {
        if (arr.size() <= 1)
            return arr;

        sort(arr.begin(), arr.end(), cmp);
        vector<dot> ans = {arr[0], arr[1]};
        for (int i = 2; i < arr.size(); ++i) {
            while (ans.size() > 1 && vect(ab(ans.back(), arr[i]), ab(arr[arr.size() - 2], arr.back())) <= 0)
                ans.pop_back();

            ans.emplace_back(arr[i]);
        }

        return ans;
    }
}

namespace lendp {
    ll hhh() {
        return 0;
    }

    unordered_map<ll, ll> dp;

    ll f() {
        ll h = hhh();
        if (dp.count(h))
            return dp[h];

        ll ans;
        dp[h] = ans;
        return ans;
    }
}

struct st {
    vector<ll> arr;
    ll sz;

    st(vector<ll> &inp) {
        ll k = 1;
        while (k < inp.size())
            k *= 2;

        sz = k * 2;
        arr.resize(sz);
        for (int i = 0; i < inp.size(); ++i)
            arr[i + k] = inp[i];

        while (--k)
            merge(k);
    }

    void merge(ll ind) {
        arr[ind] = max(arr[ind * 2], arr[ind * 2 + 1]);
    }

    ll l, r;

    ll ask(ll _l, ll _r) {
        l = _l, r = _r;
        return ask(0, sz / 2, 1);
    }

    ll ask(ll L, ll R, ll now) {
        if (L >= l && R <= r)
            return arr[now];
        else if (L >= r || R <= l)
            return LLONG_MIN;
        else
            return max(ask(L, (R + L) / 2, now * 2), ask((R + L) / 2, R, now * 2 + 1));
    }

    void se(ll ind, ll val) {
        ind += sz / 2;
        arr[ind] = val;
        while (ind > 1) {
            ind /= 2;
            merge(ind);
        }
    }
};

namespace stress {
    void gen() {

    }

    ll stupid() {
        return 0;
    }
}

void read() {

}

ll solve() {

    return 0;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll n, k, ans = 0;
    cin >> n >> k;
    vector<ll> arr(n);
    for (ll &i: arr)
        cin >> i;

    ll sum = arr[k - 1];
    multiset<ll> taken;
    for (int i = 0; i + 1 < k; ++i) {
        sum += arr[i];
        taken.insert(arr[i]);
    }

    ans = max(ans, sum);
    for (int i = k; i < n; ++i) {
        sum -= arr[i - 1];
        sum += arr[i];
        if (arr[i - 1] > *taken.begin()) {
            sum -= *taken.begin();
            taken.erase(taken.begin());
            sum += arr[i - 1];
            taken.insert(arr[i - 1]);
        }

        ans = max(ans, sum + (i - k + 1));
    }

    cout << ans + k;
    return 0;
    //*
    read();
    solve();
    return 0;
    //*/

    //ofstream test("C:\\work\\untitled\\generated_test.txt");
    ll _ = 1;
    while (cout << _ << endl, _++) {
        stress::gen();
        ll a = solve();
        ll b = stress::stupid();
        if (a != b) {

            cout << "\n\n\n" << a << ' ' << b << endl;
            return 0;
        }
    }


    return 0;
}

/*
5 3
3 7 10 1 2


*/
/*
Выберем К элементов.
Эти элементы мы возьмем.
Есть самый правый их них.
В его множество мы запихаем все что не взяли левее него. Каждое число увеличит ответ на 1.
Переберем самое правое взятое.
Левые максимальны.


*/
/*


*/
/*


*/
/*


*/