#include <bits/stdc++.h>
using namespace std;
int func(int l, int h, vector<int> arr, int n, int a) {
  if (h > n - 1 || l < 0 || h < 0 || l >= n) return 0;
  if (l > h) return 0;
  if (l == h) {
    if ((arr[l] - a) == 0) return arr[l] - a;
    return 1;
  }
  int small = l;
  for (int i = l; i <= h; i++) {
    arr[i] = arr[i] - a;
    if (arr[i] < arr[small]) small = i;
  }
  int c = 0;
  if (arr[small] > 0) c = c + arr[small];
  c = c + func(l, small - 1, arr, n, arr[small]) +
      func(small + 1, h, arr, n, arr[small]);
  if (c > (h - l + 1)) return h - l + 1;
  return c;
}
int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  int small = 0;
  int c = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] < arr[small]) small = i;
  }
  if (n == 0)
    cout << 0 << endl;
  else if (n == 1)
    cout << 1 << endl;
  else {
    if (arr[small] > 0) c = c + arr[small];
    c = c + func(0, small - 1, arr, n, arr[small]) +
        func(small + 1, n - 1, arr, n, arr[small]);
    if (c < n)
      cout << c << endl;
    else
      cout << n << endl;
  }
  return 0;
}
