#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#define endl '\n'
#define int long long

using namespace std;

int tr(int n, int k, int x, vector<int> &a) {
    vector<bool> used(n, false);
    int sum = 0;
    set<pair<int, int>> d;
    for (int i = 0; i < n; ++i) {
        d.insert({a[i], i});
    }
    while (k > x) {
        k--;
        auto it = --d.end();
        sum += 1 + (it -> first);
        used[(it -> second)] = true;
        d.erase(it);
    }
    int la = -1;
    for (int i = 0; i < n; ++i) {
        if (used[i]) {
            la = i;
        }
    }
    vector<pair<int, int>> qw;
    int ww = 1;
    for (int i = 0; i < n; ++i) {
        if (!used[i]) {
            qw.push_back({a[i] + ww, i});
            ww++;
        }
    }
    sort(qw.begin(), qw.end());
    for (int z = 0; z < x; ++z) {
        la = max(la, qw.back().second);
        used[qw.back().second] = true;
        sum += 1 + a[qw.back().second];
        qw.pop_back();
    }
    for (int j = 0; j < la; ++j) {
        if (!used[j]) {
            sum++;
        }
    }
    return sum;
}

signed main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 0; i < min(3ll, k); ++i) {
        ans = max(ans, tr(n, k, i, a));
    }
    cout << ans << endl;
    return 0;
}
