#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
int h[maxn];
int solve(int l, int r) {
  int Min = 0x3f3f3f;
  int sum, flag = l;
  for (int i = l; i <= r; i++) {
    Min = min(Min, h[i]);
  }
  for (int i = l; i <= r; i++) h[i] -= Min;
  sum = Min;
  for (int i = l; i <= r; i++) {
    if (h[i] == 0) {
      if (flag == i) {
        flag++;
        continue;
      }
      sum += solve(flag, i - 1);
      flag = i + 1;
    }
  }
  if (h[r] != 0) sum += solve(flag, r);
  sum = min(sum, r - l + 1);
  return sum;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> h[i];
  int ans = solve(1, n);
  cout << ans << endl;
  return 0;
}
