#include <bits/stdc++.h> using ll = long long; template <typename T> constexpr T INF = std::numeric_limits<T>::max() / 16; int main() { int N; std::cin >> N; std::vector<ll> A(N + 1); for (int i = 1; i <= N; i++) { std::cin >> A[i]; } std::vector<std::vector<ll>> l(N + 2, std::vector<ll>(N + 2, INF<ll>)), r(N + 2, std::vector<ll>(N + 2, INF<ll>)); l[2][N] = A[1], r[1][N - 1] = A[N]; for (int i = N - 2; i >= 0; i--) { for (int j = 1; j <= N - i; j++) { const int L = j, R = j + i; l[L + 1][R] = std::min(l[L + 1][R], std::max(l[L][R] + 1, A[L])); r[L][R - 1] = std::min(l[L][R - 1], std::max(l[L][R] + R - L + 1, A[R])); l[L + 1][R] = std::min(l[L + 1][R], std::max(r[L][R] + R - L + 1, A[L])); r[L][R - 1] = std::min(l[L][R - 1], std::max(r[L][R] + 1, A[R])); } } ll ans = INF<ll>; for (int i = 1; i <= N + 1; i++) { ans = std::min({ans, l[i][i - 1], r[i][i - 1]}); } std::cout << ans << std::endl; return 0; }