#include <bits/stdc++.h>
using namespace std;
int n, numbers[5000];
int solve(int l, int r, int h) {
  int m = 1000000000;
  for (int i = l; i < r; i++) {
    m = min(m, numbers[i] - h);
  }
  int l2 = l, r2 = l;
  int s = m;
  while (l2 != r) {
    l2 = r2;
    while (l2 < r && numbers[l2] == m + h) l2++;
    r2 = l2;
    while (r2 < r && numbers[r2] > m + h) r2++;
    if (l2 != r) s += solve(l2, r2, h + m);
  }
  return min(s, r - l);
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> numbers[i];
  }
  cout << solve(0, n, 0);
}
