//#pragma GCC optimize("unroll-loops","Ofast")
//#pragma GCC target("sse","sse2","avx","avx2")
#include <bits/stdc++.h>

#define int long long
#define F first
#define S second
using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int ans = 0;
    multiset<int> ms;
    for (int i = 0; i < n; ++i) {
        ms.insert(a[i] + 1);
    }
    for (int i = 0; i < n; ++i) {
        int now = a[i] + (i + 1);
        ms.erase(a[i] + 1);
        if (i != 0) {
            ms.insert(a[i - 1]);
        }
        auto it = ms.end();
        for (int j = 0; j < k - 1; ++j) {
            it--;
            now += *it;
        }
        ans = max(ans, now);
    }
    cout << ans;
    return 0;
}
//не забудь сохранять коды!!!