#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline string intToString(T x) {
  ostringstream q;
  q << x;
  return q.str();
}
template <typename T>
inline T myPow(T x, T n, T MOD) {
  T res = 1;
  while (n > 0) {
    if (n & 1) {
      res = 1ll * res * x % MOD;
    }
    x = 1ll * x * x % MOD;
    n /= 2;
  }
  return res;
}
template <typename T>
inline T gcd(T a, T b) {
  a = abs(a);
  b = abs(b);
  while ((a > 0) && (b > 0)) {
    if (a > b)
      a %= b;
    else
      b %= a;
  }
  return a + b;
}
int a[11111];
int rec(int l, int r) {
  if (r < l) return 0;
  int res;
  res = 0;
  int m = 1000000100;
  for (int i = l; i <= r; ++i) {
    if (a[i] < m) m = a[i];
  }
  res += m;
  for (int i = l; i <= r; ++i) {
    a[i] -= m;
  }
  int q = l;
  a[r + 1] = 0;
  for (int i = l; i <= r + 1; ++i) {
    if (a[i] == 0) {
      res += rec(q, i - 1);
      q = i + 1;
    }
  }
  if (res > r - l + 1) res = r - l + 1;
  return res;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  cout << rec(0, n - 1) << endl;
  return 0;
}
