#include <bits/stdc++.h>
using namespace std;
int n, a[5010], dp[5010][5010], ans = 1000000000;
int main() {
  int i, j;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  memset(dp, 63, sizeof(dp));
  dp[0][0] = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j <= min(a[i], n); j++) {
      dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + 1);
      if (j != a[i]) {
        dp[i + 1][min(j, a[i + 1])] =
            min(dp[i + 1][min(j, a[i + 1])], dp[i][j] + 1);
      } else {
        dp[i + 1][min(j, a[i + 1])] =
            min(dp[i + 1][min(j, a[i + 1])], dp[i][j]);
      }
    }
  }
  for (i = 0; i <= min(a[n - 1], n); i++) {
    ans = min(ans, dp[n][i]);
  }
  cout << ans << endl;
  return 0;
}
