#include <bits/stdc++.h>
const int MAXN = 1e5;
const int mod = 1e9 + 7;
using namespace std;
long long Try(long long left, long long right, long long A[],
              long long min_seg) {
  if (left >= right) return 0;
  long long min_tmp = mod;
  long long mid = 0;
  for (int i = left; i < right; i++) {
    if (A[i] < min_tmp) {
      min_tmp = A[i];
      mid = i;
    }
  }
  long long ans = min_tmp - min_seg + Try(left, mid, A, min_tmp) +
                  Try(mid + 1, right, A, min_tmp);
  return min(ans, right - left);
}
void solution_AC() {
  long long n;
  cin >> n;
  long long A[MAXN];
  for (int i = 0; i < n; i++) cin >> A[i];
  cout << Try(0, n, A, 0) << '\n';
}
int main() {
  long long test = 1;
  while (test--) {
    solution_AC();
  }
  return 0;
}
