#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
int A[maxn];
int n;
int dfs(int l, int r, int h) {
  int ans = 0;
  int last = l;
  int MIN = 0x3f3f3f3f;
  int i;
  for (i = l; i <= r; i++) {
    MIN = min(MIN, A[i]);
  }
  ans = MIN - h;
  for (i = l; i <= r; i++) {
    if (A[i] == MIN) {
      if (i > last) ans += dfs(last, i - 1, MIN);
      last = i + 1;
    } else if (i == r) {
      ans += dfs(last, i, MIN);
    }
  }
  ans = min(ans, r - l + 1);
  return ans;
}
int main() {
  int n;
  cin >> n;
  int i, j, k;
  for (i = 1; i <= n; i++) {
    scanf("%d", &A[i]);
  }
  printf("%d\n", dfs(1, n, 0));
  return 0;
}
