#include <bits/stdc++.h>

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int N, ans=0;
int A[200005];

bool check(int k){
        //cout << "k = " << k << endl;
        vector<pii> st;
        rep(i,N){
                int cur = A[i];
                bool cf = false;
                while( st.size() && st.back().X > cur ){
                        st.pop_back();
                        cf = true;
                }
                while( cur > 0 ){
                        if( st.size() && st.back().X == cur ){
                                int nx = st.back().Y + 1;
                                st.pop_back();
                                if( nx < k ){
                                        st.emplace_back(cur, nx);
                                        if( cur < A[i] ) st.emplace_back(A[i], 0);
                                        break;
                                }else{
                                        cur--;
                                        cf = true;
                                }
                        }else{
                                if( cf ){
                                        if( k == 1 ) return false;
                                        st.emplace_back(cur, 1);
                                        if( cur < A[i] ) st.emplace_back(A[i], 0);
                                }else{
                                        st.emplace_back(A[i], 0);
                                }
                                break;
                        }
                }
                if( cur <= 0 ) return false;
                // debug
                if(false){
                        int pos = 0;
                        rep(j, A[i]){
                                int ad = 0;
                                if(pos < st.size() && st[pos].X == j+1) ad = st[pos++].Y;
                                cout << char('a' + ad);
                        }
                        cout << "\t" << st << endl;
                }
        }
        return true;
}

int main(){
        ios_base::sync_with_stdio(false);

        cin >> N;
        rep(i,N) cin >> A[i];

        ll l = 0, r = 4e5;
        while(r-l > 1){
                int m = (r + l) / 2;
                (check(m) ? r : l) = m;
        }

        ans = r;

        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 4692