n = int(input()) A = list(map(int, input().split())) INF = float('inf') dp = [[[INF] * 2 for _ in range(n)] for __ in range(n)] # Initialize for single-cell intervals for i in range(n): dp[i][i][0] = A[i] dp[i][i][1] = A[i] # Process intervals of increasing length for length in range(1, n): for l in range(n - length): r = l + length # Check if we can extend to the left (to l) # From the right end of [l+1][r] candidate_left_from_right = dp[l+1][r][1] + (r - l) new_time = max(candidate_left_from_right, A[l]) if new_time < dp[l][r][0]: dp[l][r][0] = new_time # From the left end of [l+1][r] candidate_left_from_left = dp[l+1][r][0] + 1 new_time = max(candidate_left_from_left, A[l]) if new_time < dp[l][r][0]: dp[l][r][0] = new_time # Check if we can extend to the right (to r) # From the left end of [l][r-1] candidate_right_from_left = dp[l][r-1][0] + (r - l) new_time = max(candidate_right_from_left, A[r]) if new_time < dp[l][r][1]: dp[l][r][1] = new_time # From the right end of [l][r-1] candidate_right_from_right = dp[l][r-1][1] + 1 new_time = max(candidate_right_from_right, A[r]) if new_time < dp[l][r][1]: dp[l][r][1] = new_time # The answer is the minimum of the two possible end states for the full interval [0, n-1] print(min(dp[0][n-1][0], dp[0][n-1][1]))