#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

ll min(ll a, ll b) {return a < b ? a : b;}
ll min(int a, ll b) {return a < b ? a : b;}
ll min(ll a, int b) {return a < b ? a : b;}
ll min(int a, int b) {return a < b ? a : b;}

ll max(ll a, ll b) {return a > b ? a : b;}
ll max(int a, ll b) {return a > b ? a : b;}
ll max(ll a, int b) {return a > b ? a : b;}
ll max(int a, int b) {return a > b ? a : b;}

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
#define int long long
#define NAME ""

long long n, a[500000];

vector<pair<int, int> > posnum;

int check(int ans)
{
    posnum.resize(0);
    //cout << "start at ans = " << ans << endl;
    for (int i = 1; i < n; i++)
    {
        if (a[i] > a[i - 1]) continue;
        while (posnum.size() && (posnum.back()).first >= a[i]) posnum.pop_back();
        int t = 1;
        int last_looked = a[i];
        for (int j = a[i] - 1, k = (int)posnum.size() - 1; k >= 0 && j >= 0; j--, k--)
        {
            last_looked = j;
            if (posnum[k].first < j)
            {
                if (ans == 1) return 0;
                posnum.push_back({j, 2});
                t = 0;
                break;
            }
            if (posnum[k].second != ans)
            {
                posnum[k].second++;
                if (posnum[k].second > ans) return 0;
                t = 0;
                break;
            }
            posnum.pop_back();
        }
        if (t)
        {
            if (last_looked - 1 == -1 || ans == 1) return 0;
            else posnum = {{last_looked - 1, 2}};
        }
        //vector<int> digits(50, 1);
        //for (int j = 0; j < posnum.size(); j++) digits[posnum[j].first] = posnum[j].second;
        //cout << i << " : "; for (int j = 0; j < 10; j++) cout << digits[j] << " "; cout << endl;
    }
    return 1;
}

signed main()
{
    if (NAME != "")
    {
        freopen(NAME ".in", "r", stdin);
        freopen(NAME ".out", "w", stdout);
    }
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; cin >> a[i], i++) ;
    int t = 1;
    for (int i = 1; i < n; i++)
    {
        if (a[i] <= a[i - 1]) t = 0;
    }
    if (t == 1)
    {
        cout << 1;
        return 0;
    }
    int l = 0, r = n;
    while (l + 1 < r)
    {
        int mid = (l + r) / 2;
        if (check(mid))
            r = mid;
        else
            l = mid;
    }
    cout << r;
}


Measured memory_bytes: 1792