#include <bits/stdc++.h>
using namespace std;
int A[5005];
int solve(int L, int R, int H) {
  if (R < L) return 0;
  int minn = 1e9 + 9;
  for (int i = L; i <= R; i++) minn = min(minn, A[i]);
  int l = L;
  int ans = 0;
  for (int i = L; i <= R; i++) {
    if (A[i] == minn) {
      ans += solve(l, i - 1, minn);
      l = i + 1;
    }
  }
  ans += solve(l, R, minn);
  ans += minn - H;
  return min(ans, R - L + 1);
}
int main() {
  int N, i, j, k;
  cin >> N;
  for (i = 1; i <= N; ++i) cin >> A[i];
  int ans = solve(1, N, 0);
  printf("%d\n", ans);
  return 0;
}
