#include "bits/stdc++.h"

using namespace std;

#define int long long

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

    vector<pair<int, int>> s(n);

    for (int i = 0; i < n; i++) {
        cin >> s[i].first;
        s[i].second = i;
    }

    auto g = s;

    if (n == 1) {
        cout << s[0].first;
        return;
    }

    sort(s.rbegin(), s.rend());

    vector<int> f(n);
    int cnt = 0;
    for (int i = s.front().second; i >= 0; i--) {
        if (g[i].second != s[1].second) {
            f[g[i].second] = true;
            cnt++;
        }
    }

    int count = 1;

    int maxes = 0;

    for (int i = 0; i < n; i++) {
        if (!f[i]) {
            maxes = max(g[i].first + count, maxes);
            count++;
        }
    }

    cout << cnt + s[0].first + maxes << '\n';
}
signed main() {
#ifdef local
    freopen("input.txt", "r", stdin);
    freopen("output.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();
    }
}