#include <bits/stdc++.h>
long long dx[4] = {-1, 0, 1, 0};
long long dy[4] = {0, -1, 0, 1};
using namespace std;
vector<vector<long long> > g;
vector<long long> arr;
long long solve(long long l, long long r) {
  if (l > r) return 0;
  long long minimum = arr[l];
  long long idx = l;
  for (long long i = l; i <= r; i++) {
    if (arr[i] < minimum) {
      idx = i;
      minimum = arr[i];
    }
  }
  for (long long i = l; i <= r; i++) arr[i] -= minimum;
  long long ans =
      min(r - l + 1, solve(l, idx - 1) + solve(idx + 1, r) + minimum);
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    long long n;
    cin >> n;
    arr.resize(n);
    for (long long i = 0; i < n; ++i) cin >> arr[i];
    cout << solve(0, n - 1);
    cout << endl;
  }
}
