#include using ll = long long; template constexpr T INF = std::numeric_limits::max() / 16; int main() { int N; std::cin >> N; std::vector A(N + 1); for (int i = 1; i <= N; i++) { std::cin >> A[i]; } std::vector> l(N + 2, std::vector(N + 2, INF)), r(N + 2, std::vector(N + 2, INF)); 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; 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; }