//#pragma GCC optimize("O2")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
//#pragma GCC target("popcnt") 1's count

#include <vector>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <cmath>
#include <string>
#include <queue>
#include <set>
#include <unordered_set>
#include <climits> //INT_MAX, LLONG_MAX
#include <random> //mt19937
#include <numeric> //gcd
#include <bitset>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using db = double;
//#define int long long

constexpr ll inf = 2e18;

void sol() {
    ll n, k;
    cin >> n >> k;
    vector <ll> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    ll ans = 0;
    ll sm = 0;
    multiset <int> s;
    for (int i = 0; i < k - 1; i++) {
        s.insert(v[i]);
        sm += v[i];
    }
    for (int i = k - 1; i < n; i++) {
        ans = max(ans, sm + v[i] + ll(i + 1));
        if (k == 1) {
            continue;
        }
        ll temp = *s.begin();
        if (v[i] > temp) {
            sm -= temp;
            s.erase(s.begin());
            sm += v[i];
            s.insert(v[i]);
        }
    }
    cout << ans << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    cout.precision(15);

    int T = 1;
    //cin >> T;
    while (T--) {
        sol();
    }
}
