#include <bits/stdc++.h>
using namespace std;
const int maxint = 2147483647;
const int minint = -2147483647;
const unsigned int maxunint = 4294967295;
const int N = 200000;
int h[5005];
int f(int l, int r, int p) {
  int i, minh = h[l], m = l;
  for (i = l; i <= r; i++) {
    if (h[i] < minh) {
      minh = h[i];
      m = i;
    }
  }
  int ans = minh - p;
  if (m > l) ans += f(l, m - 1, minh);
  if (m < r) ans += f(m + 1, r, minh);
  if (ans > r - l + 1) ans = r - l + 1;
  return ans;
}
int main() {
  int n, i;
  cin >> n;
  for (i = 0; i < n; ++i) cin >> h[i];
  cout << f(0, n - 1, 0);
  return 0;
}
