#include <iostream>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <bitset>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <random>

using namespace std;

random_device rd;
mt19937 rnd(rd());

#define int long long

void solve() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    if (k == 1) {
        int res = 0;
        for (int i = 0; i < n; i++) {
            res = max(res, a[i] + i + 1);
        }
        cout << res;
        return;
    }
    long long res = 0;
    long long sum = 0;
    multiset<int> s;
    for (int i = 0; i < k - 1; i++) {
        s.insert(a[i]);
        sum += a[i];
    }
    for (int i = k - 1; i < n; i++) {
        res = max(res, sum + i + 1 + a[i]);
        int temp = *s.begin();
        if (temp < a[i]) {
            s.erase(s.find(temp));
            s.insert(a[i]);
            sum += a[i] - temp;
        }
    }
    cout << res;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
