## 実装

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
using namespace std;

template <typename UnaryPredicate>
int64_t binsearch(int64_t l, int64_t r, UnaryPredicate p) {
assert (l <= r);
-- l;
while (r - l > 1) {
int64_t m = l + (r - l) / 2;
(p(m) ? r : l) = m;
}
return r;
}

void normalize_tail(vector<pair<int, int> > & s) {
while (true) {
bool modified = false;
if (s.size() >= 1 and s.back().second == 0) {
s.pop_back();
modified = true;
}
if (s.size() >= 2 and s[s.size() - 2].first == s[s.size() - 1].first) {
int k = s.back().second;
s.pop_back();
s.back().second += k;
modified = true;
}
if (not modified) break;
}
}

int try_increment(int k, vector<pair<int, int> > & s, int length) {
if (s.back().first == k - 1) {
length -= s.back().second;
s.pop_back();
if (s.empty()) {
return 0;
}
}
int c = s.back().first;
assert (c + 1 < k);
s.back().second -= 1;
normalize_tail(s);
s.emplace_back(c + 1, 1);
normalize_tail(s);
return length;
}

int solve(int n, vector<int> const & a) {
return binsearch(1, n + 1, [&](int k) {
vector<pair<int, int> > s;
s.emplace_back(0, a[0]);  // "000...0"
REP (i, n - 1) {
if (a[i] < a[i + 1]) {
s.emplace_back(0, a[i + 1] - a[i]);
normalize_tail(s);
} else {
int length = a[i];
while (length > a[i + 1]) {
int delta = min(s.back().second, length - a[i + 1]);
s.back().second -= delta;
length -= delta;
normalize_tail(s);
}
length = try_increment(k, s, length);
if (not length) {
return false;
}
assert (not s.empty());
if (length < a[i + 1]) {
s.emplace_back(0, a[i + 1] - length);
normalize_tail(s);
}
}
}
return true;
});
}

int main() {
int n; cin >> n;
vector<int> a(n);
REP (i, n) cin >> a[i];
cout << solve(n, a) << endl;
return 0;
}