#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#define int long long

using namespace std;

vector<int> t, a;

void build(int v, int l, int r) {
    if (l == r - 1) {
        t[v] = a[l];
        return;
    }
    int m = (r + l) / 2;
    build(2 * v + 1, l, m);
    build(2 * v + 2, m, r);
}

int ask(int v, int l, int r, int askl, int askr) {
    if (l >= askr || r <= askl) {
        return 0;
    }
    if (l >= askl && r <= askr) {
        return t[v];
    }
    int m = (r + l) / 2;
    return ask(2 * v + 1, l, m, askl, askr) + ask(2 * v + 2, m, r, askl, askr);
}

void change(int v, int l, int r, int pos, int val) {
    if (l == r - 1) {
        t[v] = val;
        return;
    }
    int m = (r + l) / 2;
    if (pos < m) {
        change(2 * v + 1, l, m, pos, val);
    } else {
        change(2 * v + 2, m, r, pos, val);
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> b(n);
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    multiset<int> s;
    int sm = 0;
    for (int i = 0; i < k - 1; ++i) {
        s.insert(b[i]);
        sm += b[i];
    }
    int ans = 0;
    for (int i = k - 1; i < n; ++i) {
        ans = max(ans, sm + b[i] + (i - (k - 1)) + k);
        s.insert(b[i]);
        sm += b[i];
        sm -= (*s.begin());
        s.erase(s.begin());
    }
    cout << ans << '\n';
}
