#include <bits/stdc++.h>
using namespace std;
const int N = 5005, Mx = 1e9;
int n, t, ans = N, a[N], dp[N];
int main() {
  cin >> n;
  for (int i = 1; i < n + 1; i++) scanf("%d", &a[i]);
  ;
  dp[0] = 0;
  ans = n;
  for (int i = 1; i < n + 1; i++) {
    int mn = Mx;
    dp[i] = Mx;
    for (int j = i - 1; j >= 0; j--) {
      mn = min(mn, a[j]);
      dp[i] = min(dp[i], dp[j] + max(0, a[i] - mn) + i - j - 1);
    }
    ans = min(ans, dp[i] + n - i);
  }
  cout << ans;
}
