#include using namespace std; typedef long long ll; int n; ll memo[2005][2005][2]; ll a[2005]; const ll INF = 1e12; ll rec(int l, int r, int d) { if(memo[l][r][d] >= 0) return memo[l][r][d]; ll res = INF; if(l == 0 && r == n-1) { if(d == 0) res = a[0]; else res = a[n-1]; } else { if(d == 0) { if(l) res = min(res,rec(l-1,r,0) + 1); if(r < n - 1) res = min(res,rec(l,r+1,1) + r - l + 1); res = max(res,a[l]); } else { if(r < n - 1) res = min(res,rec(l,r+1,1) + 1); if(l) res = min(res,rec(l-1,r,0) + r - l + 1); res = max(res,a[r]); } } return memo[l][r][d] = res; } int main() { cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; memset(memo,-1,sizeof memo); ll ans = INF; for(int i = 0; i < n; i++) ans = min(ans,rec(i,i,0)); cout << ans << endl; }