#include "bits/extc++.h"

using namespace std;
using namespace __gnu_pbds;

using ll = long long;

template<typename T>
istream &operator>>(istream &is, vector<T> &a);

template<typename T>
ostream &operator<<(ostream &os, vector<T> &a);


using ordered_set = tree<int, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    cin >> a;

    vector<ll> smax(n);
    smax[n - 1] = a[n - 1] + n;
    for (int i = n - 2; i >= 0; --i) {
        smax[i] = max(smax[i + 1], a[i] + i + 1);
    }

    ll ans = 0;
    for (int l = 0; l < n - 1; ++l) {
        ans = max(ans, a[l] + l + smax[l + 1] - l);
    }
    cout << ans << "\n";
}

template<typename T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &v: a) is >> v;
    return is;
}

template<typename T>
ostream &operator<<(ostream &os, vector<T> &a) {
    for (auto v: a) os << v << " ";
    return (os << "\n");
}
