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

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

#define int ll

mt19937 g(52);
int get_rand(int l, int r) {
    return uniform_int_distribution<int>(l, r)(g);
}

int n, k = 2;
vector<int> a;
list<int> l;

void gen() {
    n = get_rand(2, 100);
    a.clear();
    l.clear();
    a.resize(n + 1);
    for (int i = 1; i <= n; i++) {
        a[i] = get_rand(1, 1000000000);
        l.push_back(a[i]);
    }
}

void input() {
    cin >> n >> k;
    a.resize(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        l.push_back(a[i]);
    }
}

int solve_ok() {
    int mx = a[1] + 1;
    int mxid = 1;
    for (int i = 1; i <= n; i++) {
        if (a[i] + i >= mx) {
            mx = a[i] + i;
            mxid = i;
        }
    }

    int ans = mx;

    int mx2 = 0;

    for (int i = mxid + 1; i <= n; i++) {
        mx2 = max(mx2, a[i] + i - mxid);
    }

    int mx3 = 0;
    for (int i = 1; i < mxid; i++) {
        mx3 = max(mx3, a[i] + 1);
    }
    ans = max(mx + mx2, mx + mx3 - 1);
    return ans;
}

int split() {
    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 = 0;
    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 max(mx + mx2, mx + mx3 - 1);
}

void solve() {
    input();
    cout << solve_ok();
}

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();
    }
}
