#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define yes() cout << "YES\n"
#define no() cout << "NO\n"
using ll = long long;
using ld = long double;
using namespace std;
using namespace __gnu_pbds;

template<typename K>
using oset = tree<K, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    for (int& i : a) cin >> i;

    if (k == 2) {
        int ans = 0;
        for (int i = 0; i < n; i++) {
            a[i] += (i + 1);
        }

        vector<int> pref(n), suff(n);
        for (int i = 0; i < n; i++) {
            if (i == 0) {
                pref[0] = a[0];
            }

            pref[i] = max(pref[i - 1], a[i]);
        }

        for (int i = n - 1; i >= 0; i--) {
            if (i == n - 1) {
                suff[n - 1] = a[n - 1];
            }

            suff[i] = max(suff[i + 1], a[i]);
        }

        for (int i = 0; i < n - 1; i++) {
            ans = max(ans, pref[i] + suff[i + 1] - i - 1);
        }

        cout << ans << "\n";
        return;
    }

    int ans = 0;
    set<pair<int, int>> st;
    for (int i = 0; i < n; i++) {
        st.insert({-a[i], i});
    }

    int t = k - 1;
    while (t > 0) {
        t--;
        int idx = st.begin()->second;
        st.erase(st.begin());
        ans += a[idx] + 1;
        a[idx] = 0;
    }

    int prime = 0;
    int mx = -1e18;
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) continue;
        prime++;
        mx = max(mx, a[i] + prime);
    }

    cout << mx + ans << "\n";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--) {
        solve();
    }
}