#include <bits/stdc++.h>

using namespace std;

#define int long long

signed main() {
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin(), a.end());
    int sum = 0;
    int l = 0;
    for (int j = n - 1; j >= n - k; j--) {
        sum += a[j].first;
        l = max(l, a[j].second + 1);
    }
    cout << sum + l << "\n";
}
