#include "bits/stdc++.h"
using namespace std;
# define int long long
# define all(a) a.begin(), a.end()


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
    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(all(a), greater<>());
//    a.resize(k + 1);
    int good = -1;
    for(int i = 0; i < k; ++i){
        if(a[i].second == n - 1){
            good = i;
            break;
        }
    }
    if(good != -1){
        a.resize(k);
        int sum = 0;
        for(auto &[i, j] : a){
            sum += i;
        }
        cout << sum + n;
    } else {
        vector<int> p(n);
        int sum = 0;
        for(int i = 1; i < k; ++i){
            p[a[i].second] = 1;
            sum += a[i].first;
        }
        for(int i = 1; i < n; ++i){
            p[i] = p[i - 1] + i;
        }
        int pos = -1;
        for(int i = 0; i < n; ++i){
            if(a[i].second == n - 1){
                pos = i;
            }
        }
        int mx = a[pos].first + (n - k + 1);
        for(int i = k - 1; i < n; ++i){
            mx = max(mx, a[i].first + a[i].second + 1 - p[a[i].second]);
        }
        cout << sum + mx;
    }
//    a.resize(k + 1);
////    bool good = false;
////    for(auto &i : a){
////        if(i.second == n - 1){
////            good = true;
////            break;
////        }
////    }

    return 0;
}