#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<unordered_set>
#include<unordered_map>
#include<iomanip>
#include<random>
#include<bitset>
#include<ctime>

#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2")

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using uint = unsigned int;

ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
mt19937 mt(time(0));
const int N = 5e5 + 2, inf = 1e9 + 100, mod = 1e9 + 7, mod2 = 998244353, P = 257;
const ll llinf = 1e18 + 100;
int n, k;
ll a[N];

void solve() {
	cin >> n >> k;
	for (int i = 0; i < n; ++i) cin >> a[i];
	ll ans = 0, sufmx = -1;
	for (int i = n - 2; i >= 0; --i) {
		sufmx = max(sufmx, a[i]) + 1;
		ans = max(ans, a[i] + i + 1 + a[n - 1] + sufmx);
	}
	cout << ans;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int tt = 1;
	//cin >> tt;
	while (tt--) {
		solve();
		cout << '\n';
		cout.flush();
	}
	return 0;
}