#include <bits/stdc++.h>
#define int long long

using namespace std;

vector <int> arr1;
int ans1 = 0;
int n, k;
vector <int> p;

void solve() {
    if (p.size() == n) {
        vector <int> maxx(k);
        vector <int> cnt(k);
        for (int i = 0; i < n; ++i) {
            cnt[p[i]]++;
            maxx[p[i]] = max(maxx[p[i]], arr1[i] + cnt[p[i]]);
        }
        int c = 0;
        for (int i = 0; i < k; ++i) {
            if (cnt[i] == 0) return;
            c += maxx[i];
        }
        ans1 = max(ans1, c);
        return;
    }
    for (int i = 0; i < k; ++i) {
        p.push_back(i);
        solve();
        p.pop_back();
    }
}
int solve1(vector <int> arr) {
    set <pair <int, int>> s;
    int summ = 0;
    for (int i = 0; i < k; ++i) {
        s.insert({arr[i], i});
        summ += arr[i];
    }
    int ans = summ + k;
    for (int i = k; i < n; ++i) {
        ans = max(ans, summ - (*s.begin()).first + arr[i] + i + 1);
        s.insert({arr[i], i});
        summ += arr[i] - (*s.begin()).first;
        s.erase(s.begin());
    }
    return ans;
}

signed main() {
    cin >> n >> k;
    vector <int> arr(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    cout << solve1(arr);
    return 0;
}
