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

using namespace __gnu_pbds;
using namespace std;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//less_equal

//#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,bmi2,fma,popcnt")

#define int long long
#define x first
#define y second

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (auto& i : v) {
        cin >> i;
    }
    int mx = 0, indmx = -1, mx2 = 0, indmx2 = -1;
    for (int i = 0; i < n; i++) {
        if (v[i] + i + 1 > mx) {
            indmx = i;
            mx = v[i] + i + 1;
        }
    }

    for (int i = 0; i < n; i++) {
        if (v[i] + i + 1 > mx2 && i != indmx) {
            indmx2 = i;
            mx2 = v[i] + i + 1;
        }
    }
    int ans = mx;
    for (int i = 0; i < n; i++) {
        if (i < indmx) {
            ans = max(mx + v[i], ans);
        }else if (i == indmx) {
            if (indmx2 < indmx) {
                ans = max(mx2 + v[i], ans);
            }else {
                ans = max(mx2 + 1 + v[i], ans);
            }
        }else {
            ans = max(mx + v[i], ans);
        }
    }
    cout << ans;
}

signed main() {
#ifdef lisie_bimbi
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    //cin.tie(nullptr);
    //ios_base::sync_with_stdio(false);
#endif
    int _ = 1;
    //cin >> _;
    while (_--) {
        solve();
    }
}