import java.io.*; import java.util.*; class InputValidator implements Closeable { final InputStream in; final int NO_BUFFER = -2; int buffer; public InputValidator(final InputStream in) { this.in = in; buffer = NO_BUFFER; } int read() throws IOException { final int res = buffer == NO_BUFFER ? in.read() : buffer; buffer = NO_BUFFER; return res; } void unread(int ch) throws IOException { buffer = ch; } // [low, high] long nextLong(long low, long high) throws IOException { long val = 0; int ch = -1; while (true) { ch = read(); if (!Character.isDigit(ch)) break; val = val * 10 + ch - '0'; check(val <= high); } check(ch >= 0); check(val >= low); unread(ch); return val; } int nextInt(int low, int high) throws IOException { return (int)nextLong(low, high); } int[] nextInts(int n, int low, int high) throws IOException { int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = nextInt(low, high); if (i + 1 != n) space(); } newLineOrEOF(); return res; } void space() throws IOException { int ch = read(); check(ch == ' '); } void newLine() throws IOException { int ch = read(); if (ch == '\r') ch = read(); check(ch == '\n'); } void newLineOrEOF() throws IOException { int ch = read(); check(ch == '\r' || ch == '\n' || ch < 0); } void check(boolean b) { if (!b) throw new RuntimeException(); } @Override public void close() throws IOException { } } public class _483_Validate { public static void main(String[] args) throws IOException { new _483_Validate().solve(); } void solve() throws IOException { try (final InputValidator in = new InputValidator(System.in)) { // try (final Scanner in = new Scanner(System.in)) { int n = in.nextInt(1, 2000); in.newLine(); A = in.nextInts(n, 0, 1_000_000_000); 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)); } }