#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int n, ___________________[N];
int ______________________________________________(int l, int r) {
  int ans1 = r - l + 1;
  int ______ = ___________________[l];
  for (int i = l; i <= r; ++i) {
    ______ = min(______, ___________________[i]);
  }
  int ans2 = ______;
  for (int i = l; i <= r; ++i) {
    ___________________[i] -= ______;
  }
  for (int i = l; i <= r; ++i) {
    if (___________________[i] > 0) {
      int j = i;
      while (___________________[j + 1] > 0 && j <= r) ++j;
      ans2 += ______________________________________________(i, j);
      i = j + 1;
    }
  }
  return min(ans1, ans2);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &___________________[i]);
  }
  printf("%d", ______________________________________________(1, n));
  return 0;
}
