#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:108777216")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <utility>
#include <algorithm>
#include <ctime>
using namespace std;

int const MAX_N = 256 * 1024;

int s[MAX_N], new_s[MAX_N];
map<int, pair<int, int> > ms;  // bg, len, value
map<int, pair<int, int> >::iterator iter_1;

map<int, pair<int, int> >::iterator get_value(int p) {
	map<int, pair<int, int> >::iterator iter = ms.lower_bound(p);
	if (iter == ms.end())
		--iter;
	else if (iter->first > p)
		--iter;
	return iter;
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &s[i]);

	int t = 1;
	for (int i=1; i<n; i++)
		if (s[i] <= s[i - 1]) {
			t = 0;
			break;
		}
	if (t) {
		cout << "1";
		return 0;
	}

	for (int i = 1; i + 1 < n; i++)
		s[i] = min(s[i], max(s[i - 1], s[i + 1]) + 1);
	int new_n = 0;
	int k = 0;
	do {
		int bg = k;
		while (k + 1 < n && s[k] < s[k + 1]) k++;
		int en = k;
		k++;
		new_s[new_n++] = s[bg];
		if (en > bg)
			new_s[new_n++] = s[en];
	} while (k < n);
	n = new_n;
	for (int i = 0; i < n; i++) s[i] = new_s[i];
	for (int i = 1; i + 1 < n; i++)
		s[i] = min(s[i], max(s[i - 1], s[i + 1]) + 1);

	int sum = 0;
	for (int i = 0; i + 1 < n; i++)
		if (s[i] < s[i + 1])
			sum++;
	int mn = s[0];
	for (int i = 0; i < n; i++) mn = min(mn, s[i]);
	int cnt_ones = 0;
	for (int i = 0; i < n; i++) cnt_ones += s[i] == 1;

	int a = 1, b = 1;
	for (int i=0; i<n; i++)
		if (i % 2 == 0) {
			if (s[i] != 1) a = 0;
		}
		else {
			if (s[i] != 1) b = 0;
		}

	if (a || b) {
		cout << cnt_ones;
		return 0;
	}

	int cnt_mn = 0;
	for (int i = 0; i < n; i++)
		if (s[i] == mn) cnt_mn++;

	int down = 0, up = cnt_mn + 1;
	while (up > down) {
		int mid = (up + down) / 2;
		long long QQ = 1;
		for (int j = 0; j < mn; j++) {
			QQ *= mid;
			if (QQ >= cnt_mn)
				break;
		}
		if (QQ >= cnt_mn)
			up = mid;
		else
			down = mid + 1;
	}
	int x = down;

	down = max(x, max(cnt_ones, 2)), up = n + 1 + 3 - sum;
	while (down <= up) {
		int mid = down;

		int Ok = 1;
		long long QQ = 1;
		for (int j = 0; j < mn; j++) {
			QQ *= mid;
			if (QQ >= n)
				break;
		}
		if (QQ < n) {
			ms.clear();
			ms[0] = make_pair(s[0], 1);
			for (int i = 1; i < n; i++) {
				if (s[i] > s[i - 1]) {
					int x = s[i - 1];
					while (i<n && s[i] > s[i - 1]) i++;
					i--;
					ms[x] = make_pair(s[i] - x, 1);
					continue;
				}
				if (s[i] <= s[i - 1]) {
					int p = s[i] - 1;
					map<int, pair<int, int> >::iterator iter = get_value(p);
					int value = iter->second.second;
					int new_value = value + 1;
					if (new_value > mid) {
						while (new_value > mid) {
							p--;
							if (p < 0) {
								Ok = 0;
								break;
							}
							if (p < iter->first) {
								iter_1 = iter;
								iter--;
								ms.erase(iter_1);
							}
							new_value = iter->second.second + 1;
						}
						if (!Ok)
							break;

						ms[p] = make_pair(1, new_value);
						if (s[i] - 1 - p > 0)
							ms[p + 1] = make_pair(s[i] - 1 - p, 1);
					}
					else {
						int bg = iter->first;
						int en = bg + iter->second.first - 1;

						if (bg >= p) {
							ms.erase(iter);

							if (en > bg)
								ms[bg + 1] = make_pair(en - bg, value);

							ms[bg] = make_pair(1, new_value);
						}
						else if (en <= p) {
							ms[bg].first--;
							if (ms[bg].first <= 0)
								ms.erase(get_value(bg));

							ms[p] = make_pair(1, new_value);
						}
						else {
							ms[bg].first = p - bg;
							ms[p] = make_pair(1, new_value);
							ms[p + 1] = make_pair(en - p, value);
						}
					}
				}
			}
		}

		if (Ok) {
			break;
		}
		down++;
	}
	
	cout << down;
	return 0;
}

Measured memory_bytes: 13568