
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>

using namespace std;

#define ll long long
#define FOR(i, s, f) for(ll (i) = (s); (i) < (f); (i)++)
const long long INF = 1e9;

struct vertex{
    ll sum = 0;
    vertex *l, *r;
    vertex() = default;
    vertex(ll sum): sum(sum){}
    vertex(ll sum, vertex* l, vertex* r): sum(sum), l(l), r(r){}
};

vertex* build(ll tl, ll tr){
    if (tl == tr) return new vertex(0);
    ll mid = (tl + tr) / 2;
    vertex *l = build(tl, mid), *r = build(mid + 1, tr);
    return new vertex(l->sum + r->sum, l, r);
}

ll get(vertex* x, ll l, ll r, ll tl, ll tr){
    if (tl > r || tr < l) return 0;
    if (l <= tl && tr <= r) return x->sum;
    ll mid = (tl + tr) / 2;
    return get(x->l, l, r, tl, mid) + get(x->r, l, r, mid + 1, tr);
}

void upd(vertex* x, ll ind, ll val, ll tl, ll tr){
    if (tl > ind || tr < ind) return;
    if (tl == tr){
        x->sum += val;
        return;
    }
    ll mid = (tl + tr) / 2;
    upd(x->l, ind, val, tl, mid);
    upd(x->r, ind, val, mid + 1, tr);
    x->sum = x->l->sum + x->r->sum;
}


void solve(){
    ll n, k;
    cin >> n >> k;
    vector<ll> arr(n);
    FOR(i, 0, n) cin >> arr[i];
    ll m = 0;
    FOR(i, 0, n) if (arr[i] > arr[m]) m = i;
    ll ans = 0, cnt = 0;
    ans = arr[m] + m + 1;
    if (m == n - 1){
        ll m2 = 0;
        FOR(i, 0, n - 1) if (arr[i] > arr[m2]) m2 = i;
        cout << n + arr[m2] + arr[m];
        return;
    }
    vector<ll> brr;
    map<ll, ll> sz;
    FOR(i, m + 1, n){
        brr.push_back(arr[i]);
    }
    sort(brr.begin(), brr.end());
    brr.erase(unique(brr.begin(), brr.end()), brr.end());
    FOR(i, 0, brr.size()) sz[brr[i]] = i;
    vertex* root = build(0, brr.size());
    ll ma = 0;
    FOR(i, m + 1, n){
        upd(root, sz[arr[i]], 1, 0, brr.size());
        ll p = get(root, 0, sz[arr[i]], 0, brr.size());
        if (p + arr[i] > ma) ma = p + arr[i];
    }
    cout << ans + ma;
}

int main() {
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
