#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void checkmin(T &a, const T &b) {
  if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, const T &b) {
  if (b > a) a = b;
}
const int inf = 1e9 + 10;
const int maxn = 5e3 + 10;
int n, dp[maxn][maxn], a[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  a[n] = n;
  for (int i = 0; i < maxn; i++)
    for (int j = 0; j < maxn; j++) dp[i][j] = inf;
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= min(n, a[i]); j++) {
      if (j + 1 <= min(n, a[i])) {
        checkmin(dp[i][j + 1], dp[i][j] + 1);
      }
      int h = min(j, a[i + 1]);
      checkmin(dp[i + 1][h], dp[i][j] + (j != a[i]));
    }
  }
  int ans = n;
  for (int i = 0; i <= min(n, a[n - 1]); i++) checkmin(ans, dp[n][i]);
  printf("%d\n", ans);
  return 0;
}
