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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == 0) {
        v.clear();
        return 0;
    }
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    return i;
}
void read_cr() {
    fgets(_buf, 256, stdin);
}

int N;
vector<int> a;
vector<ii> b;

vector<int> to_str(ll x, int base, int w, int cap)
{
    vector<int> s(min(w,cap), 0);
    int i = s.size()-1;
    bool overflow = false;
    while (x > 0) {
        if (i < 0) {
            if (s.size() == w) return vi{-1};
            break;
        }
        s[i--] = x % base;
        x /= base;
    }
    int shift = w - s.size();
    if (shift > 0) {
        rep(i, s.size()) {
            if (i+shift < cap) s[i + shift] = s[i];
            s[i] = 0;
        }
    } else if (shift < 0) {
        for (int i=shift-1; i>=0; --i) if (s[i] > 0) return vi{-1};
        rep(i, s.size()) {
            if (i+shift < cap) {
                s[i] = s[i + shift];
                s[i + shift] = 0;
            } else {
                s[i] = 0;
            }
        }
    }
    return s;
}

long long bin_to_num( const vector<int> &vec )
{
  long long num = 0;
  for (int i=vec.size()-1; i>=0; i--) num = num * 2 + vec[i];
  return num;
}


vi add(vi& a, vi& b, int base) {
    int al=a.size(), bl=b.size();
    int L = max(al, bl);
    vi c(L, 0);
    rep(i,L) {
        if (i < al) c[i] += a[i];
        if (i < bl) c[i] += b[i];
    }
    int carry = 0;
    for (int i=L-1; i>=0; --i) {
        c[i] += carry;
        carry = c[i] / base; c[i] %= base;
    }
    if (carry != 0) return vi{-1};
    return c;
}

bool possible(int t){
    int z=1, y=N+t+1;
    while (y) { y /= t; z++; }
    int MX = max(20, z*3+1);

    int L = b.size();
    ll x = 0;
    vi ks;
    int w = b[0].first, h = b[0].second;
    vi v = to_str(h-1, t, w, MX);
    if (v[0] == -1) return false;
    int lastw = w;
    for (int i=1; i<L; ++i) {
        int w = b[i].first, h = b[i].second;
        if (v.size() > w) v.resize(w);
        int x = (w < lastw) ? h : h-1;
        vi v2 = to_str(x, t, w, MX);
        if (v2[0] == -1) return false;
        v = add(v, v2, t);
        if (v[0] == -1) return false;
        lastw = w;
    }
    return true;
}

int solve(){
    if (N == 1) return 1;

    int incc=0;
    rep(i,N-1) if (a[i] < a[i+1]) ++incc;
    if (incc == N-1) return 1;
    int last = -1, cnt = 0;
    rep(i,N) {
        if (a[i] == last) {
            ++cnt;
        } else {
            if (cnt) b.pb(ii(last, cnt));
            last = a[i];
            cnt = 1;
        }
    }
    if (cnt) b.pb(ii(last, cnt));

    int lo=1, hi=N;
    while (lo+1 < hi) {
        int mi = mid(lo, hi);
        if (possible(mi)) {
            hi = mi;
        } else {
            lo = mi;
        }
    }
    return hi;
}

int main() {
    N = loadvec(a);
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 5108