import sys sys.setrecursionlimit(int(1e6)) input = lambda: sys.stdin.readline().rstrip("\r\n") MOD = 998244353 INF = int(4e18) def min2(a: int, b: int) -> int: return a if a < b else b def max2(a: int, b: int) -> int: return a if a > b else b if __name__ == "__main__": n = int(input()) nums = list(map(int, input().split())) dp = [[INF] * n for _ in range(n)] dp[0][n - 1] = 0 dp[n - 1][0] = 0 for w in range(n, 1, -1): for i in range(n - w + 1): j = i + w - 1 dp[i][j] = min2(dp[i][j], dp[j][i] + (j - i - 1)) dp[j][i] = min2(dp[j][i], dp[i][j] + (j - i - 1)) dp[i + 1][j] = min2(dp[i + 1][j], max2(dp[i][j], nums[i]) + 1) dp[j - 1][i] = min2(dp[j - 1][i], max2(dp[j][i], nums[j]) + 1) res = INF for i in range(n): res = min2(res, max2(dp[i][i], nums[i])) print(res)