#include <bits/stdc++.h>
using namespace std;
int n;
int dp[5005][5005];
int a[5005];
int solve(int i, int j) {
  if (i == n) return 0;
  if (dp[i][j] != -1) return dp[i][j];
  int ans1 = INT_MAX, ans2 = INT_MAX;
  ans1 = solve(i + 1, min(a[i], j));
  if (a[i] > min(a[i], j)) ans1 += 1;
  if (a[i] <= n && a[i] >= j) {
    ans2 = (a[i] - j) + solve(i + 1, a[i]);
  }
  return dp[i][j] = min(ans1, ans2);
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  memset(dp, -1, sizeof dp);
  int ans1 = INT_MAX, ans2 = INT_MAX;
  if (a[0] <= n) ans1 = a[0] + solve(1, a[0]);
  ans2 = 1 + solve(1, 0);
  cout << min(ans1, ans2) << endl;
}
