#include <bits/stdc++.h>
using namespace std;
int h[5010];
const int INF = 1e9 + 7;
int cal(int l, int r) {
  if (l > r) return 0;
  int minn = INF;
  for (int i = l; i <= r; i++) minn = min(h[i], minn);
  for (int i = 1; i <= r; i++) h[i] -= minn;
  int now = minn;
  int s = l;
  for (int i = 1; i <= r; i++) {
    if (i == r && h[i] > 0) {
      now += cal(s, i);
    } else if (h[i] == 0) {
      now += cal(s, i - 1), s = i + 1;
    }
  }
  return min(r - l + 1, now);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
  printf("%d\n", cal(1, n));
}
