#include <bits/stdc++.h>
using namespace std;
long long minStrokes(vector<long long> v, long long i, long long j) {
  if (i == j) {
    if (v[i] != 0)
      return 1;
    else
      return 0;
  }
  if (j < i) {
    return 0;
  }
  long long ind = min_element(v.begin() + i, v.begin() + j + 1) - v.begin();
  long long val = v[ind];
  for (int x = i; x <= j; x++) {
    v[x] -= val;
  }
  return val + min(minStrokes(v, i, ind - 1), ind - i) +
         min(j - ind, minStrokes(v, ind + 1, j));
}
int main(void) {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  cout << min(n, minStrokes(a, 0, n - 1));
}
