#include <bits/stdc++.h>
using namespace std;
int n;
int h[5001];
int solve(int l, int r, int lh) {
  if (l == r) return 1;
  if (l > r) return 0;
  int res = 0, minh = 1e9, la = l - 1;
  for (int i = l; i <= r; i++) minh = min(minh, h[i]);
  res = minh - lh;
  for (int i = l; i <= r; i++)
    if (h[i] == minh) res += solve(la + 1, i - 1, minh), la = i;
  res += solve(la + 1, r, minh);
  return min(res, r - l + 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
  printf("%d", solve(1, n, 0));
  return 0;
}
