#include <bits/stdc++.h>

using namespace std;

#define int long long

int INF = 1e17;
vector<vector<int>> g;

vector<int> get(vector<int>& s) {
    set<pair<int, int>> mai;
    mai.insert({-s[0], 0});
    int cnt = 0;
    vector<int> ans(s.size());
    while (!mai.empty()) {
        ans[mai.begin()->second] = cnt;
        cnt++;
        int u = mai.begin()->second;
        mai.erase(mai.begin());
        for (auto to : g[u]) {
            mai.insert({-s[to], to});
        }
    }
    return ans;
}

void sovel() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto& to : a) cin >> to;
    set<int> now;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (now.size() < k) {
            ans += a[i] + 1;
            now.insert(a[i] + 1);
        } else {
            ans = max(ans, ans - *now.begin() + n - k - 1);
        }
    }
    cout << ans;
}

signed main() {
    int t = 1;
    //cin >> t;
    while (t--) {
        sovel();
    }
}
