#include <bits/stdc++.h>
using namespace std;
const int N = 1e4;
int a[N];
int solve(int l, int r) {
  if (l > r) return 0;
  int minn = 0x3f3f3f3f, pos = -1;
  for (int i = l; i <= r; ++i) {
    if (minn > a[i]) {
      minn = a[i];
      pos = i;
    }
  }
  for (int i = l; i <= r; ++i) {
    a[i] -= minn;
  }
  return min(r - l + 1, solve(l, pos - 1) + solve(pos + 1, r) + minn);
}
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  cout << solve(1, n);
}
