    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <set>
    #include <map>

    #define all(a) a.begin(), a.end()

    using namespace std;
    using ll = long long;
    using ld = long double;
    using pii = pair<int, int>;
    using pll = pair<ll, ll>;

    vector<ll> a;

    bool cmp(int const &i, int const &j) {
        return a[i] < a[j];
    }

    void solve() {
        int n, k;
        cin >> n >> k;
        a.resize(n);
        vector<int> b(n);
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
            b[i] = i;
        }

        if (k == 1) {
            ll ans = 0;
            for (int i = 0; i < n; ++i) {
                ans = max(ans, a[i] + i + 1);
            }
            cout << ans;
            return;
        }

        sort(all(b), cmp);
        bool f = true;
        vector<ll> kostyl(n);
        for (int i = n - 1; i >= n - k; --i) {
            kostyl[b[i]] = 1;
        }
        int cnt = 1;
        for (int i = 0; i < n; ++i) {
            if (kostyl[i] == 0) {
                kostyl[i] = ++cnt;
            }
        }
        ll s = 0;
        vector<ll> z;
        for (int i = 0; i < n; ++i) {
            if (kostyl[i] != 1) {
                s = max(s, a[i] + kostyl[i]);
            } else {
                z.push_back(a[i] + 1);
            }
        }
        sort(all(z));
        for (int i = 1; i < z.size(); ++i) s += z[i];
        cout << s;
    }

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

        solve();
    }