#include <bits/stdc++.h>
// created [2019/11/12] 19:50:04
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wsign-conversion"

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
using uint = unsigned int;
using usize = std::size_t;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template<typename T> constexpr T popcount(const T u) { return u ? static_cast<T>(__builtin_popcountll(static_cast<u64>(u))) : static_cast<T>(0); }
template<typename T> constexpr T log2p1(const T u) { return u ? static_cast<T>(64 - __builtin_clzll(static_cast<u64>(u))) : static_cast<T>(0); }
template<typename T> constexpr T msbp1(const T u) { return log2p1(u); }
template<typename T> constexpr T lsbp1(const T u) { return __builtin_ffsll(u); }
template<typename T> constexpr T clog(const T u) { return u ? log2p1(u - 1) : static_cast<T>(u); }
template<typename T> constexpr bool ispow2(const T u) { return u and (static_cast<u64>(u) & static_cast<u64>(u - 1)) == 0; }
template<typename T> constexpr T ceil2(const T u) { return static_cast<T>(1) << clog(u); }
template<typename T> constexpr T floor2(const T u) { return u == 0 ? static_cast<T>(0) : static_cast<T>(1) << (log2p1(u) - 1); }
template<typename T> constexpr bool btest(const T mask, const usize ind) { return static_cast<bool>((static_cast<u64>(mask) >> ind) & static_cast<u64>(1)); }
template<typename T> void bset(T& mask, const usize ind) { mask |= (static_cast<T>(1) << ind); }
template<typename T> void breset(T& mask, const usize ind) { mask &= ~(static_cast<T>(1) << ind); }
template<typename T> void bflip(T& mask, const usize ind) { mask ^= (static_cast<T>(1) << ind); }
template<typename T> void bset(T& mask, const usize ind, const bool b) { (b ? bset(mask, ind) : breset(mask, ind)); }
template<typename T> constexpr T bcut(const T mask, const usize ind) { return ind == 0 ? static_cast<T>(0) : static_cast<T>((static_cast<u64>(mask) << (64 - ind)) >> (64 - ind)); }
template<typename T> bool chmin(T& a, const T& b) { return (a > b ? a = b, true : false); }
template<typename T> bool chmax(T& a, const T& b) { return (a < b ? a = b, true : false); }
constexpr unsigned int mod                  = 1000000007;
template<typename T> constexpr T inf_v      = std::numeric_limits<T>::max() / 4;
template<typename Real> constexpr Real pi_v = Real{3.141592653589793238462643383279502884};

template<typename T>
T read()
{
    T v;
    return std::cin >> v, v;
}
template<typename T, typename... Args>
auto read(const usize size, Args... args)
{
    std::vector<decltype(read<T>(args...))> ans(size);
    for (usize i = 0; i < size; i++) { ans[i] = read<T>(args...); }
    return ans;
}
template<typename... Types>
auto reads() { return std::tuple<std::decay_t<Types>...>{read<Types>()...}; }
#    define SHOW(...) static_cast<void>(0)

template<typename T>
std::vector<T> make_v(const usize size, const T v) { return std::vector<T>(size, v); }
template<typename... Args>
auto make_v(const usize size, Args... args) { return std::vector<decltype(make_v(args...))>(size, make_v(args...)); }


namespace bbst_node {
template<typename Key, typename Node, typename Comp>
struct key_node : Node
{
    using ptr       = key_node* const;
    using const_ptr = const ptr;
    using key_type  = Key;
    using comp_type = Comp;
    key_node() : Node{}, key{Key{}} {}
    template<typename... Args>
    key_node(const Key& key, Args... args) : Node{args...}, key{key} { this->sz = 1; }
    void pull_up(const_ptr l, const_ptr r) { Node::pull_up(l, r); }
    void push_down(ptr l, ptr r) { Node::push_down(l, r); }
    template<typename Value>
    void set(const Value& val, const_ptr l, const_ptr r) { Node::set(val, l, r); }
    template<typename Op>
    void act(const Op& o) { Node::act(o); }
    friend std::ostream& operator<<(std::ostream& os, const key_node& n) { return os << "key=" << n.key << ":" << static_cast<Node>(n); }
    const key_type key;
};
struct node
{
    using ptr       = node* const;
    using const_ptr = const ptr;
    void pull_up(const_ptr l, const_ptr r) { sz = (l ? l->sz : 0UL) + 1UL + (r ? r->sz : 0UL); }
    void push_down(ptr, ptr) {}
    friend std::ostream& operator<<(std::ostream& os, const node& n) { return os << "size=" << n.sz; }
    usize sz = 0;
};
template<typename Value>
struct value_node
{
    using ptr        = value_node* const;
    using const_ptr  = const ptr;
    using value_type = Value;
    value_node()     = default;
    value_node(const value_type& value) : value{value}, sz{1} {}
    void pull_up(const_ptr l, const_ptr r) { sz = (l ? l->sz : 0UL) + 1UL + (r ? r->sz : 0UL); }
    void push_down(ptr, ptr) {}
    void set(const value_type& val, const_ptr, const_ptr) { value = val; }
    friend std::ostream& operator<<(std::ostream& os, const value_node& n) { return os << "value=" << n.value; }
    value_type value{};
    usize sz = 0;
};
template<typename ValueMonoid>
struct merge_node
{
    using ptr               = merge_node* const;
    using const_ptr         = const ptr;
    using value_monoid_type = ValueMonoid;
    using value_type        = typename value_monoid_type::value_type;
    merge_node()            = default;
    merge_node(const value_type& value) : value{value}, merged{value}, sz{1} {}
    void pull_up(const_ptr l, const_ptr r) { sz = (l ? l->sz : 0UL) + 1UL + (r ? r->sz : 0UL), merged = value_monoid_type::merge((l ? l->merged : value_monoid_type::id()), value_monoid_type::merge(value, (r ? r->merged : value_monoid_type::id()))); }
    void push_down(ptr, ptr) {}
    void set(const value_type& val, const_ptr l, const_ptr r) { value = val, pull_up(l, r); }
    friend std::ostream& operator<<(std::ostream& os, const merge_node& n) { return os << "value=" << n.value << ",merged=" << n.merged; }
    value_type value = value_monoid_type::id(), merged = value_monoid_type::id();
    usize sz = 0;
};
template<typename MonoidAct>
struct lazy_node
{
    using ptr                  = lazy_node* const;
    using const_ptr            = const ptr;
    using monoid_act_type      = MonoidAct;
    using value_monoid_type    = typename monoid_act_type::value_monoid_type;
    using operator_monoid_type = typename monoid_act_type::operator_monoid_type;
    using value_type           = typename value_monoid_type::value_type;
    using operator_type        = typename operator_monoid_type::operator_type;
    lazy_node()                = default;
    lazy_node(const value_type& value) : value{value}, merged{value}, sz{1} {}
    void pull_up(const_ptr l, const_ptr r) { sz = (l ? l->sz : 0UL) + 1UL + (r ? r->sz : 0UL), merged = value_monoid_type::merge((l ? l->merged : value_monoid_type::id()), value_monoid_type::merge(value, (r ? r->merged : value_monoid_type::id()))); }
    void push_down(ptr l, ptr r)
    {
        if (op == operator_monoid_type::id()) { return; }
        if (l) { l->act(op); }
        if (r) { r->act(op); }
        op = operator_monoid_type::id();
    }
    void set(const value_type& val, const_ptr l, const_ptr r) { value = val, pull_up(l, r); }
    void act(const operator_type& o) { value = monoid_act_type::apply(o, value, 1), merged = monoid_act_type::apply(o, merged, sz), op = operator_monoid_type::compose(op, o); }
    friend std::ostream& operator<<(std::ostream& os, const lazy_node& n) { return os << "value=" << n.value << ",merged=" << n.merged << ",op=" << n.op; }
    value_type value = value_monoid_type::id(), merged = value_monoid_type::id();
    operator_type op = operator_monoid_type::id();
    usize sz         = 0;
};
}  // namespace bbst_node
template<typename NodeData>
class base_splaytree
{
private:
    class node
    {
        using ptr       = node*;
        using const_ptr = const node* const;
        using tree      = ptr;

    public:
        node() : node_data{} {}
        template<typename... Args>
        node(Args... args) : node_data{args...} {}
        usize size() const { return node_data.sz; }
        const NodeData& data() const { return node_data; }
        template<typename Operator>
        void act(const Operator& op) { node_data.act(op); }
        template<typename Value>
        void set(const Value& value) { node_data.set(value, data_ptr_of(l), data_ptr_of(r)), pull_up(); }
        friend std::ostream& operator<<(std::ostream& os, const node& n) { return os << "[" << n.node_data << "]"; }
        bool has_left() const { return l; }
        bool has_right() const { return r; }
        bool has_parent() const { return p; }
        const node& left() const { return deptr(l); }
        const node& right() const { return deptr(r); }
        const node& parent() const { return deptr(p); }
        static node& deptr(ptr x) { return x ? (*x) : empty_node; }
        static ptr merge(tree tp1, tree tp2)
        {
            if (not tp1) { return tp2; }
            if (not tp2) { return tp1; }
            ptr lp2    = kth_ptr(tp2, 0);
            return tp2 = (lp2->splay(), lp2), tp2->push_down(), tp2->l = tp1, tp1->p = tp2, tp2->pull_up(), tp2;
        }
        static std::pair<ptr, ptr> split_at(tree tp, const usize pos) { return split(tp, kth_ptr(tp, pos)); }
        static std::tuple<ptr, ptr, ptr> split_range(tree tp, const usize pos_min, const usize pos_sup)
        {
            auto ts = split_at(tp, pos_min), trs = split_at(ts.second, pos_sup - pos_min);
            return std::make_tuple(ts.first, trs.first, trs.second);
        }
        template<typename Key>
        static std::pair<ptr, ptr> split_lower(tree tp, const Key& key) { return split(tp, lower_bound(tp, key)); }
        template<typename Key>
        static std::pair<ptr, ptr> split_upper(tree tp, const Key& key) { return split(tp, upper_bound(tp, key)); }
        template<typename Key>
        static std::tuple<ptr, ptr, ptr> split_key_range(tree tp, const Key& key_min, const Key& key_max)
        {
            auto ts = split_lower(tp, key_min), trs = split_upper(ts.second, key_max);
            return std::make_tuple(ts.first, trs.first, trs.second);
        }

    private:
        static NodeData* data_ptr_of(ptr x) { return x ? &(x->node_data) : nullptr; }
        static usize size_of(const_ptr x) { return x ? x->size() : 0UL; }
        bool is_root() const { return (not p) or (p->l != this and p->r != this); }
        int is_left() const { return is_root() ? 0 : (p->l == this ? 1 : -1); }
        void pull_up() { node_data.pull_up(data_ptr_of(l), data_ptr_of(r)); }
        void push_down() { node_data.push_down(data_ptr_of(l), data_ptr_of(r)); }
        void rot()
        {
            ptr pp        = p->p;
            const int isl = p->is_left();
            if (is_left() == 1) {
                p->l = r, (r ? r->p : p) = p, r = p, p->p = this;
            } else {
                p->r = l, (l ? l->p : p) = p, l = p, p->p = this;
            }
            p->pull_up(), pull_up();
            p = pp;
            if (isl == 0) { return; }
            (isl == 1 ? pp->l : pp->r) = this, pp->pull_up();
        }
        void splay()
        {
            while (not is_root()) { (p->is_root() ? rot() : is_left() == p->is_left() ? (p->rot(), rot()) : (rot(), rot())); }
        }
        static std::pair<ptr, ptr> split(tree tp, ptr p)
        {
            if (not p) { return {tp, nullptr}; }
            tp     = (p->splay(), p);
            ptr lp = tp->l;
            if (not lp) { return std::make_pair(nullptr, tp); }
            return tp->push_down(), lp->p = nullptr, tp->l = nullptr, tp->pull_up(), std::make_pair(lp, tp);
        }
        static ptr kth_ptr(const tree tp, usize k)
        {
            for (ptr p = tp; p;) {
                p->push_down();
                const usize ind = size_of(p->l);
                if (ind == k) { return p; }
                p = (k < ind ? p->l : (k -= (ind + 1), p->r));
            }
            return nullptr;
        }
        template<typename Key>
        static ptr lower_bound(const tree tp, const Key& key)
        {
            static typename NodeData::comp_type comp{};
            ptr ans = nullptr;
            for (ptr p = tp; p;) { p->push_down(), p = (comp(p->data().key, key) ? p->r : (ans = p, p->l)); }
            return ans;
        }
        template<typename Key>
        static ptr upper_bound(const tree tp, const Key& key)
        {
            static typename NodeData::comp_type comp{};
            ptr ans = nullptr;
            for (ptr p = tp; p;) { p->push_down(), p = (comp(key, p->data().key) ? (ans = p, p->l) : p->r); }
            return ans;
        }
        static node empty_node;  // inline変数を使いたいでござる
        NodeData node_data;
        ptr l = nullptr, r = nullptr, p = nullptr;
    };
    using ptr       = node*;
    using const_ptr = const node* const;
    ptr root        = nullptr;

public:
    base_splaytree() {}
    base_splaytree(const ptr r) : root{r} {}
    template<typename... Args>
    base_splaytree(Args... args) : root{new node{args...}} {}
    bool empty() const { return not root; }
    usize size() const { return root ? root->sz : 0UL; }
    const node& top() const { return node::deptr(root); }
    const node at(const usize pos) { return fold_range(pos, pos + 1); }
    const node fold_range(const usize pos_min, const usize pos_sup)
    {
        auto ts        = node::split_range(root, pos_min, pos_sup);
        const node ans = node::deptr(std::get<1>(ts));
        return root    = node::merge(std::get<0>(ts), node::merge(std::get<1>(ts), std::get<2>(ts))), ans;
    }
    template<typename Key>
    const node fold_key_range(const Key& key_min, const Key& key_max)
    {
        auto ts        = node::split_key_range(root, key_min, key_max);
        const node ans = node::deptr(std::get<1>(ts));
        return root    = node::merge(std::get<0>(ts), node::merge(std::get<1>(ts), std::get<2>(ts))), ans;
    }
    template<typename Key>
    const node fold_lower(const Key& key)
    {
        auto ts        = node::split_lower(root, key);
        const node ans = node::deptr(ts.first);
        return root    = node::merge(ts.first, ts.second), ans;
    }
    template<typename Key>
    const node fold_upper(const Key& key)
    {
        auto ts        = node::split_upper(root, key);
        const node ans = node::deptr(ts.second);
        return root    = node::merge(ts.first, ts.second), ans;
    }
    template<typename Value>
    base_splaytree& set_at(const usize pos, const Value& value)
    {
        auto ts = node::split_range(root, pos, pos + 1);
        std::get<1>(ts)->set(value);
        return root = node::merge(std::get<0>(ts), node::merge(std::get<1>(ts), std::get<2>(ts))), *this;
    }
    template<typename Key, typename Value>
    base_splaytree& set(const Key& key, const Value& value)
    {
        auto ts = node::split_key_range(root, key, key);
        std::get<1>(ts)->set(value);
        return root = node::merge(std::get<0>(ts), node::merge(std::get<1>(ts), std::get<2>(ts))), *this;
    }
    template<typename Op>
    base_splaytree& act_range(const usize pos_min, const usize pos_sup, const Op& op)
    {
        auto ts = node::split_range(root, pos_min, pos_sup);
        std::get<1>(ts)->act(op);
        return root = node::merge(std::get<0>(ts), node::merge(std::get<1>(ts), std::get<2>(ts))), *this;
    }
    template<typename Key, typename Op>
    base_splaytree& act_key_range(const Key& key_min, const Key& key_max, const Op& op)
    {
        auto ts = node::split_key_range(root, key_min, key_max);
        std::get<1>(ts)->act(op);
        return root = node::merge(std::get<0>(ts), node::merge(std::get<1>(ts), std::get<2>(ts))), *this;
    }
    base_splaytree& merge(base_splaytree&& t) { return root = node::merge(root, t.root), *this; }
    base_splaytree split_at(const usize pos)
    {
        auto ts     = node::split_at(root, pos);
        return root = ts.first, base_splaytree(ts.second);
    }
    std::pair<base_splaytree, base_splaytree> split_range(const usize pos_min, const usize pos_sup)
    {
        auto ts     = node::split_range(root, pos_min, pos_sup);
        return root = std::get<0>(ts), std::make_pair(base_splaytree(std::get<1>(ts)), base_splaytree(std::get<2>(ts)));
    }
    base_splaytree& erase_at(const usize pos)
    {
        auto ts = node::split_at(root, pos), trs = node::split_at(ts.second, 1);
        return root = node::merge(ts.first, trs.second), *this;
    }
    base_splaytree& insert_at(const usize pos, base_splaytree&& t)
    {
        auto ts     = node::split_at(root, pos);
        return root = node::merge(node::merge(ts.first, t.root), ts.second), *this;
    }
    template<typename Key>
    base_splaytree split_lower(const Key& key)
    {
        auto ts     = node::split_lower(root, key);
        return root = ts.first, base_splaytree(ts.second);
    }
    template<typename Key>
    base_splaytree split_upper(const Key& key)
    {
        auto ts     = node::split_upper(root, key);
        return root = ts.first, base_splaytree(ts.second);
    }
    template<typename Key>
    std::pair<base_splaytree, base_splaytree> split_key_range(const Key& key_min, const Key& key_max)
    {
        auto ts     = node::split_key_range(root, key_min, key_max);
        return root = std::get<0>(ts), std::make_pair(base_splaytree(std::get<1>(ts)), base_splaytree(std::get<2>(ts)));
    }
    base_splaytree& insert(const node& n)
    {
        auto ts     = node::split_lower(root, n.data().key);
        return root = node::merge(node::merge(ts.first, new node{n}), ts.second), *this;
    }
    std::vector<node> data() const
    {
        if (empty()) { return std::vector<node>{}; }
        auto dfs = [&](auto&& self, const node& n) -> std::vector<node> {
            std::vector<node> ans;
            if (n.has_left()) {
                for (auto&& e : self(self, n.left())) { ans.emplace_back(e); }
            }
            ans.push_back(n);
            if (n.has_right()) {
                for (auto&& e : self(self, n.right())) { ans.emplace_back(e); }
            }
            return ans;
        };
        return dfs(dfs, *root);
    }
};
template<typename NodeData>
typename base_splaytree<NodeData>::node base_splaytree<NodeData>::node::empty_node = node{};
template<typename Value>
using splaytree = base_splaytree<bbst_node::value_node<Value>>;
template<typename Key, typename Comp = std::less<Key>>
using mset_splaytree = base_splaytree<bbst_node::key_node<Key, bbst_node::node, Comp>>;
template<typename Key, typename Value, typename Comp = std::less<Key>>
using mmap_splaytree = base_splaytree<bbst_node::key_node<Key, bbst_node::value_node<Value>, Comp>>;
template<typename ValueMonoid>
using merge_splaytree = base_splaytree<bbst_node::merge_node<ValueMonoid>>;
template<typename MonoidAct>
using lazy_splaytree = base_splaytree<bbst_node::lazy_node<MonoidAct>>;
int main()
{
    const auto n = read<usize>();
    const auto a = read<usize>(n);

    auto b = a;
    std::sort(b.begin(), b.end());
    usize eq = 0;
    for (usize i = 1; i < n; i++) {
        if (b[i - 1] == b[i]) { eq++; }
    }
    if (eq == n - 1) { return std::cout << n << std::endl, 0; }
    if (eq == 0 and a == b) { return std::cout << 1 << std::endl, 0; }

    auto ok = [&](const usize k) {
        mmap_splaytree<usize, usize> number;
        for (usize i = 1; i < n; i++) {
            if (a[i] <= a[i - 1]) {
                for (int j = (int)a[i] - 1; j >= 0; j--) {
                    auto ts = number.split_key_range(j, j);
                    if (ts.first.empty()) {
                        ts.first.insert({j, 1});
                        ts.first.merge(std::move(ts.second));
                        number.merge(std::move(ts.first));
                        break;
                    }
                    const usize prev = ts.first.top().data().value;
                    if (prev == k - 1) {
                        if (j == 0) { return false; }
                        ts.first.set(j, 0);
                        ts.first.merge(std::move(ts.second));
                        number.merge(std::move(ts.first));
                    } else {
                        ts.first.set(j, prev + 1);
                        ts.first.merge(std::move(ts.second));
                        number.merge(std::move(ts.first));
                        break;
                    }
                }
            } else {
                number.split_lower(a[i - 1]);
            }
        }
        return true;
    };
    usize inf = 1, sup = n + 1;
    while (sup - inf > 1) {
        const usize mid       = (inf + sup) / 2;
        (ok(mid) ? sup : inf) = mid;
    }
    std::cout << sup << std::endl;
    return 0;
}


Measured memory_bytes: 224768