#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000001;
int a[5010];
int dfs(int l, int r, int now) {
  int i, ans = 0;
  int h = INF;
  if (l == r) return 0;
  for (i = l; i < r; i++) h = min(h, a[i]);
  ans += h - now;
  int L = l;
  for (i = l; i < r; i++) {
    if (a[i] == h) {
      ans += dfs(L, i, h);
      L = i + 1;
    }
  }
  ans += dfs(L, r, h);
  return min(r - l, ans);
}
int main() {
  int i, n;
  while (scanf("%d", &n) == 1) {
    int m = 0;
    for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    int ans = dfs(0, n, 0);
    printf("%d\n", ans);
  }
  return 0;
}
