#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N];
int f(int l, int r) {
  if (l > r) return 0;
  if (l == r) return min(a[l], 1);
  int k = 1e9, x = l;
  for (int i = l; i <= r; i++) {
    if (k > a[i]) {
      k = a[i];
      x = i;
    }
  }
  int cnt = 0;
  for (int i = l; i <= r; i++) {
    if (a[i]) cnt++;
    a[i] -= k;
  }
  return min(cnt, k + f(l, x - 1) + f(x + 1, r));
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  cout << f(1, n);
  return 0;
}
