import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class _483 { public static void main(String[] args) throws IOException { new _483().solve(); } void solve() throws IOException { try (final Scanner in = new Scanner(System.in)) { int n = in.nextInt(); A = new int[n]; for (int i = 0; i < n; i++) { A[i] = in.nextInt(); } memo = new int[n][n][2]; for (int[][] me : memo) for (int[] mo : me) Arrays.fill(mo, -1); int ans = INF; for (int i = 0; i < n; i++) { ans = Math.min(ans, rec(i, i, 0)); } System.out.println(ans); } } int[] A; final int INF = 1<<30; int[][][] memo; int rec(int l, int r, int lr) { if (l < 0) return INF; if (r >= A.length) return INF; if (r - l + 1 == A.length) return A[lr == 0 ? l : r]; if (memo[l][r][lr] != -1) return memo[l][r][lr]; final int x = lr == 0 ? l : r; int ans = INF; ans = Math.min(ans, (rec(l - 1, r, 0) + x - l + 1)); ans = Math.min(ans, (rec(l, r + 1, 1) + r - x + 1)); ans = Math.max(A[x], ans); return memo[l][r][lr] = ans; } // for debug static void dump(Object... o) { System.err.println(Arrays.deepToString(o)); } }