#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

#define int ll
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using ordered_set = __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

mt19937 rnd(time(0));

inline void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
#ifdef LOCAL
    for (auto &x: a) x = rnd() % 8;
    for (auto &x: a) cout << x << " ";
    cout << "\n";
#else
    for (auto &x: a) cin >> x;
#endif
    auto b = a;
    multiset<int> al;
    sort(rall(b));
    for (int i = 0; i < k; i++) al.insert(b[i]);
    int ans = 0;
    for (auto &x: al) ans += x;
    if (al.find(a.back()) != al.end()) {
        cout << ans + n << " ";
    } else {
        al.erase(al.find(b[k - 1]));
        int lst;
        for (int i = n - 1; i >= 0; i--) {
            if (al.find(a[i]) != al.end()) {
                lst = i;
                break;
            }
        }
        ans -= b[k - 1];
        ans += lst + 1;
        int now = 0;
        int mx = 0;
        for (int i = lst + 1; i < n; i++) {
            now++;
            mx = max(mx, a[i] + now);
        }
        ans += mx;
        int ans1 = 0;
        al.clear();
        for (int i = 0; i < k - 1; i++) al.insert(b[i]);
        for (auto &x: al) ans1 += x;
        ans1 += k - 1;
        now = 0;
        mx = 0;
        int f = 1;
        for (int i = n - 1; i >= 0; i--) {
            if (a[i] == b[k - 1]) {
                lst = i;
                break;
            }
        }
        for (int i = 0; i < n; i++) {
            if (al.find(a[i]) == al.end()) {
                now++;
                mx = max(mx, now + a[i]);
            } else {
                al.erase(al.find(a[i]));
            }
        }
        ans = max(ans, ans1 + mx);
        cout << ans << " ";
    }
#ifdef LOCAL
    int ans1 = 0;
    for (int ms = 1; ms < (1 << n) - 1; ms++) {
        int now1 = 0, now2 = 0;
        int mx1 = 0, mx2 = 0;
        if (ms == 1)
            int kwf = 0;
        for (int i = 0; i < n; i++) {
            if ((ms >> i) & 1) {
                now1++;
                mx1 = max(mx1, a[i] + now1);
            } else {
                now2++;
                mx2 = max(mx2, a[i] + now2);
            }
        }
        ans1 = max(ans1, mx1 + mx2);
        if (ans1 == 17) {
            int kwe = 0;
        }
    }
    cout << ans1;
#endif
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) solve();
}