#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

#define int ll

const int maxn = 5e5 + 1;
int a[maxn];

struct t_ans {
    int val;
    list<int> l1, l2;
};

int split(list<int> l) {
    int mx = l.front() + 1;
    int mxid = 1;
    auto mxit = l.begin();
    {
        auto it = l.begin();
        for (int i = 1; mxit != l.end(); it++, i++) {
            if (*it + i >= mx) {
                mx = *it + i;
                mxid = i;
                mxit = it;
            }
        }
    }

    int ans = mx;

    int mx2 = 0;
    {
        auto it = mxit;
        it++;
        for (int i = mxid + 1; it != l.end(); it++, i++) {
            mx2 = max(mx2, *it + i - mxid);
        }
    }

    int mx3 = (mxid == 1 ? 0 : l.front() + 1);
    auto mx3it = l.begin();
    auto it = l.begin();
    for (int i = 1; it != mxit; it++, i++) {
        if (*it + 1 > mx3) {
            mx3 = *it + 1;
            mx3it = it;
        }
    }
    return ans = max(mx + mx2, mx + mx3 - 1);
}

list<int> la;

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

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        la.emplace_back(a[i]);
    }

    cout << split(la);
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
#ifdef local
    freopen("i.txt", "r", stdin);
    freopen("o.txt", "w", stdout);
#endif
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
}
