#include "bits/stdc++.h"

using namespace std;

#define int long long

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

    vector<int> s(n);
    map<int, int> cnt;
    set<int, greater<>> d;

    for (int i = 0; i < n; i++) {
        cin >> s[i];
        cnt[s[i]]++;
        d.emplace(s[i]);
    }

    int sum = 0;

    map<int, int> used;

    for (int i = 0; i < k - 1; i++) {
        sum += s[i] + 1;
        cnt[s[i]]--;
        used[s[i]] = true;
    }

    cnt[s[n - 1]]--;
    int count = 1;
    for (int i = n - 2; i >= 0; i--) {
        if (used[s[i]])
            break;
        cnt[s[i]]--;
        count++;
    }

    int maxes = 0;

    int cnt1 = count;
    for (int i = n - 1; i >= n - count; i--) {
        maxes = max(maxes, s[i] + cnt1);
        cnt1--;
    }

    for (auto i: cnt) {
        sum += i.second;
    }

    cout << sum + maxes << '\n';
}
signed main() {
#ifdef local
    freopen("input.txt", "r", stdin);
    freopen("answer.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int akbalin = 1;
    //    cin >> akbalin;

    for (int i = 1; i <= akbalin; i++) {
        solve();
    }
}