#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

void print_stack(stack<pll> &org){
    string res = "";
    stack<pll> st(org);
    vector<pll> tmp;
    while(!st.empty()){  
        pll x = st.top();
        st.pop();
        tmp.push_back(x);
        REP(i, x.second) res += char('a'+x.first);
    }
    reverse(res.begin(), res.end());
    reverse(tmp.begin(), tmp.end());
    cout << tmp << endl;
    cout << res << endl;
    return;
}

void erase_doub(stack<pll> &st){
    if(st.size()>1){
        pll tmp1 = st.top();st.pop();
        pll tmp2 = st.top();
        if(tmp1.first == tmp2.first){
            st.pop();
            st.push({tmp1.first, tmp1.second+tmp2.second});
        }else{
            st.push(tmp1);
        }
    }
    return;
}

bool check(ll N, vector<ll> &A, ll x){
    stack<pll> st;
    ll len = 0;
    REP(i, N){
        //dump(i)
        if(st.empty()){

            st.push({0, A[i]});
            erase_doub(st);

            len = A[i];
        }else{
            if(len<A[i]){
                if(st.top().first == 0){
                    len -= st.top().second;
                    st.pop();
                }

                st.push({0, A[i]-len});
                erase_doub(st);

                len = A[i];
            }else{
                pll tmp = st.top();
                while(len-tmp.second>=A[i]){
                    st.pop();
                    len -= tmp.second;
                    tmp = st.top();
                }
                st.pop();
                len -= tmp.second;
                if(tmp.first == x-1){
                    if(st.empty()){
                        //cerr<<"NO\n\n";
                        return false;
                    }else{
                        tmp = st.top();
                        st.pop();
                        if(tmp.second>1){
                            st.push({tmp.first, tmp.second-1});
                            erase_doub(st);
                        }

                        st.push({tmp.first+1, 1});
                        erase_doub(st);

                        if(A[i]-len>0){
                            st.push({0, A[i]-len});
                            erase_doub(st);
                        }
                        len = A[i];
                    }
                }else{
                    if(A[i]-len-1>0){
                        st.push({tmp.first, A[i]-len-1});
                        erase_doub(st);
                    }

                    st.push({tmp.first+1, 1});
                    erase_doub(st);

                    len = A[i];
                }
            }
        }
        //print_stack(st);
    }
    //cerr<<"OK\n\n";
    return true;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    
    
    ll ng = 0;
    ll ok = N+1;
    while(ok-ng>1){
        ll md = (ok+ng)/2;
        //dump(md);
        if(check(N, A, md)) ok = md;
        else ng = md; 
    }
    cout << ok << endl;
    
    

    /*
    REP(num, N){
        dump(num+1)
        check(N, A, num+1);
    }
    */
    
    //check(N, A, 3);
    return 0;
}

Measured memory_bytes: 1792