#include <bits/stdc++.h>
using namespace std;
int *fences;
int paintInterval(int first, int last, int height) {
  if (first >= last) return 0;
  int minHeight = first;
  for (int i = first; i < last; i++)
    if (fences[minHeight] > fences[i]) minHeight = i;
  return min(last - first,
             fences[minHeight] - height +
                 paintInterval(first, minHeight, fences[minHeight]) +
                 paintInterval(minHeight + 1, last, fences[minHeight]));
}
int main() {
  int n;
  cin >> n;
  fences = new int[n];
  for (int i = 0; i < n; i++) cin >> fences[i];
  cout << paintInterval(0, n, 0);
}
