#include <bits/stdc++.h>
using namespace std;
const int N = 10000;
int a[N], b[N];
int print(int l, int r, int h) {
  int mid = l;
  if (l > r) return 0;
  if (l == r) return (a[l] > h);
  for (int i = l; i <= r; i++)
    if (a[i] < a[mid]) mid = i;
  return min(r - l + 1, print(l, mid - 1, a[mid]) + print(mid + 1, r, a[mid]) +
                            a[mid] - h);
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cout << print(0, n - 1, 0) << endl;
  return 0;
}
