#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int n, k;
#define all(a) a.begin(), a.end()
vector<ll> a;
void solve() {
    cin >> n >> k;
    a.resize(n);
    for (auto &i : a) cin >> i;
    set<pair<int, int>> cur;
    for (int i = 0; i < n; ++i) {
        cur.insert({a[i] + i + 1, i});
    }
    ll mx = 0;
    ll ans = 0;
    for (int i = 0; i < n - 1; ++i) {
        mx = max(mx, a[i] + i + 1);
        cur.erase(cur.find({a[i] + i + 1, i}));
        ans = max(ans, mx + (*--cur.end()).first - i - 1);
    }
    cout << ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}
