#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44

using namespace std;

const int MAXN = (int) 2e5;

struct Segm {
    int l, r;
    int val;
    bool operator <(const Segm &other) const {
        return r < other.r;
    }
};

multiset < Segm > mst;
int len[MAXN + 1], n;

inline int check(int lim) {
    mst.insert({1, len[1], 1});
    bool ans = 1;
    for(int i = 2; i <= n; i++) {
        if(len[i] > len[i - 1]) {
            auto it = *prev(mst.end());
            Segm cur = {len[i - 1] + 1, len[i], 1};
            if(it.val == 1) {
                mst.erase(prev(mst.end()));
                cur.l = it.l;
            }
            mst.insert(cur);
        }
        else {
            if(mst.lower_bound({0, len[i] + 1, 0}) != mst.end()) {
                auto cur = *mst.lower_bound({0, len[i] + 1, 0});
                mst.erase(mst.lower_bound({0, len[i] + 1, 0}), mst.end());
                if(cur.l <= len[i]) {
                    mst.insert({cur.l, len[i], cur.val});
                }
            }
            auto it = *prev(mst.end());
            if(it.val == lim) {
                if(mst.size() == 1) {
                    ans = 0;
                    mst.erase(mst.begin());
                    mst.insert({len[i], len[i], ans});
                    if(len[i] > 1) {
                        mst.insert({1, len[i] - 1, ans - 1});
                    }
                }
                else {
                    it = *prev(prev(mst.end()));
                    mst.erase(prev(prev(mst.end())));
                    if(it.l < it.r) {
                        mst.insert({it.l, it.r - 1, it.val});
                        mst.insert({it.r, it.r, it.val + 1});
                    }
                    else {
                        Segm cur = {it.r, it.r, it.val + 1};
                        if(mst.lower_bound({0, it.r, 0}) != mst.begin()) {
                            auto itr = *prev(mst.lower_bound({0, it.r, 0}));
                            if(itr.val == it.val + 1) {
                                cur.l = itr.l;
                                mst.erase(prev(mst.lower_bound({0, it.r, 0})));
                            }
                        }
                        mst.insert(cur);
                    }
                    it = *prev(mst.end());
                    mst.erase(prev(mst.end()));
                    mst.insert({it.l, it.r, 1});
                }
            }
            else {
                mst.erase(prev(mst.end()));
                if(it.l < it.r) {
                    mst.insert({it.l, it.r - 1, it.val});
                    mst.insert({it.r, it.r, it.val + 1});
                }
                else {
                    Segm cur = {it.r, it.r, it.val + 1};
                    if(mst.lower_bound({0, it.r, 0}) != mst.begin()) {
                        auto itr = *prev(mst.lower_bound({0, it.r, 0}));
                        if(itr.val == it.val + 1) {
                            cur.l = itr.l;
                            mst.erase(prev(mst.lower_bound({0, it.r, 0})));
                        }
                    }
                    mst.insert(cur);
                }
            }
        }
    }
    mst.clear();
    return ans;
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    for(i = 1; i <= n; i++) {
        cin >> len[i];
    }
    int res = 0;
    for(int step = 1 << 30; step; step >>= 1) {
        if(check(res + step) == 0) {
            res += step;
        }
    }
    cout << res + 1;
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 1152