#include <bits/stdc++.h>
using namespace std;
int dp(int i, int coins, vector<int>& dur, vector<vector<int>>& mem) {
if (mem[i][coins] != -1) {
return mem[i][coins];
}
if (i == mem.size()-1) {
return coins+1;
}
if (dur[i+1]-1 >= coins) {
int r1 = -1;
int r2 = -1;
r1 = dp(i+1, coins, dur, mem);
if (dur[i+1]-1 >= coins+1) {
r2 = dp(i+1, coins+1, dur, mem);
}
mem[i][coins] = max(r1, r2, coins+1);
} else {
mem[i][coins] = coins+1;
}
return mem[i][coins];
}
int main() {
int n, m;
cin >> n >> m;
if (n == 1) {
vector<int> dur(m);
int max_dur = 0;
for (int i = 0; i < m; i++) {
cin >> dur[i];
if (dur[i] > max_dur) {
max_dur = dur[i];
}
}
vector<vector<int>> mem1(m, vector<int>(max_dur+1, -1));
vector<vector<int>> mem2(m, vector<int>(max_dur+1, -1));
int max_coins = 0;
for (int i = 0; i < m; i++) {
int res = dp(i, 0, dur, mem1);
if (res > max_coins) {
max_coins = res;
}
}
reverse(dur.begin(), dur.end());
for (int i = 0; i < m; i++) {
int res = dp(i, 0, dur, mem2);
if (res > max_coins) {
max_coins = res;
}
}
cout << max_coins << endl;
/*
int max_coins = 1;
for (int i = 0; i < m; i++) {
int p = i;
int coins = 1;
while (p < m-1) {
if (dur[p+1]-1 >= coins) {
p++;
coins++;
} else {
break;
}
}
if (coins > max_coins) {
max_coins = coins;
}
}
reverse(dur.begin(), dur.end());
for (int i = 0; i < m; i++) {
int p = i;
int coins = 1;
while (p < m-1) {
if (dur[p+1]-1 >= coins) {
p++;
coins++;
} else {
break;
}
}
if (coins > max_coins) {
max_coins = coins;
}
}
/*
int p1 = 0;
int p2 = 0;
int coins_carried = 1;
while (p1 < m) {
p1++;
coins_carried--;
while (p2 < m-1) {
if (dur[p2+1]-1 >= coins_carried) {
p2++;
coins_carried++;
} else {
break;
}
}
if (coins_carried > max_coins) {
max_coins = coins_carried;
}
}
reverse(dur.begin(), dur.end());
p1 = 0;
p2 = 0;
coins_carried = 1;
while (p1 < m) {
p1++;
coins_carried--;
p2 = max(p2, p1);
while (p2 < m-1) {
if (dur[p2+1]-1 >= coins_carried) {
p2++;
coins_carried++;
} else {
break;
}
}
if (coins_carried > max_coins) {
max_coins = coins_carried;
}
}
*/
}
}