#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }





int N;
vector<long long> a;
using pll = pair<long long, long long>;

void normalize(vector<pll> &nums) {
    if (nums.size() > 1) {
        if (nums[nums.size()-1].first == nums[nums.size()-2].first) {
            nums[nums.size()-2].second += nums[nums.size()-1].second;
            nums.pop_back();
        }
    }
}

void zouka(vector<pll> &nums) {
    if (nums.back().second == 1) {
        nums.back().first += 1;
    }
    else {
        nums.back().second--;
        nums.push_back(pll(nums.back().first+1, 1));
    }
    normalize(nums);
}

int main() {
    while (cin >> N) {
        a.resize(N);
        for (int i = 0; i < N; ++i) cin >> a[i];
        long long low = 0, high = N+1;
        while (high - low > 1) {
            long long mid = (low + high) / 2;

            //cout << "---------------" << endl; COUT(mid);

            vector<pll> nums;
            nums.push_back(pll(0, a[0]));

            bool ok = true;
            for (int i = 1; i < N; ++i) {
                if (a[i-1] < a[i]) {
                    if (nums.back().first == 0) {
                        nums.back().second += a[i] - a[i-1];
                    }
                    else {
                        nums.push_back(pll(0, a[i]-a[i-1]));
                    }
                }
                else {
                    long long sum = 0;
                    while (nums.size() > 0 && sum + nums.back().second <= a[i-1] - a[i]) {
                        sum += nums.back().second;
                        nums.pop_back();
                    }
                    long long rem = a[i-1] - a[i] - sum;
                    nums.back().second -= rem;

                    if (nums.back().first == mid-1) {
                        if (nums.size() == 1) {
                            ok = false;
                            break;
                        }
                        long long num = nums.back().second;
                        nums.pop_back();
                        zouka(nums);
                        nums.push_back(pll(0, num));
                    }
                    else {
                        zouka(nums);
                    }
                }
                normalize(nums);

                //cout << i << ": " << a[i] << endl;
                //COUT(nums); cout << endl;
            }

            if (ok) high = mid;
            else low = mid;
        }
        cout << high << endl;
    }
}






















Measured memory_bytes: 1792