#include <bits/stdc++.h> using namespace std; using ll=long long; #define int ll #define FOR(i,a,b) for(int i=int(a);i<int(b);i++) #define REP(i,b) FOR(i,0,b) #define MP make_pair #define PB push_back #define ALL(x) x.begin(),x.end() #define REACH cerr<<"reached line "<<__LINE__<<endl #define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl using pi=pair<int,int>; using vi=vector<int>; using ld=long double; template<class T,class U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os<<"("<<p.first<<","<<p.second<<")"; return os; } template<class T> ostream& operator <<(ostream& os,const vector<T>& v){ os<<"["; REP(i,(int)v.size()){ if(i)os<<","; os<<v[i]; } os<<"]"; return os; } int read(){ int i; scanf("%lld",&i); return i; } void printSpace(){ printf(" "); } void printEoln(){ printf("\n"); } void print(int x,int suc=1){ printf("%lld",x); if(suc==1) printEoln(); if(suc==2) printSpace(); } string readString(){ static char buf[3341919]; scanf("%s",buf); return string(buf); } char* readCharArray(){ static char buf[3341919]; static int bufUsed=0; char* ret=buf+bufUsed; scanf("%s",ret); bufUsed+=strlen(ret)+1; return ret; } template<class T,class U> void chmax(T& a,U b){ if(a<b) a=b; } template<class T,class U> void chmin(T& a,U b){ if(a>b) a=b; } template<class T> T Sq(const T& t){ return t*t; } const int inf=LLONG_MAX/3; const int Nmax=2017; int dp[Nmax][Nmax][2]; signed main(){ int n=read(); vi a; REP(i,n)a.PB(read()); REP(i,n)REP(j,n)dp[i][j][0]=dp[i][j][1]=inf; dp[0][n-1][0]=max(a[0]+n-1,a[n-1]); dp[0][n-1][1]=max(a[0],a[n-1]+n-1); for(int d=n-1;d>=1;d--) REP(l,n-d){ int r=l+d; chmin(dp[l+1][r][0],max(a[l+1]+(r-(l+1)),dp[l][r][0])); chmin(dp[l+1][r][1],max(a[l+1],dp[l][r][0]+(r-(l+1)))); chmin(dp[l][r-1][1],max(a[r-1]+((r-1)-l),dp[l][r][1])); chmin(dp[l][r-1][0],max(a[r-1],dp[l][r][1]+((r-1)-l))); } int ans=inf; REP(i,n) chmin(ans,min(dp[i][i][0],dp[i][i][1])); cout<<ans<<endl; }