#include <bits/stdc++.h>
using namespace std;
const int N = 5001;
long long int dp[N][N];
long long int a[N];
int n;
long long int solve(int i, long long int prev) {
  if (i == n) return 0;
  if (dp[i][prev] != -1) return dp[i][prev];
  long long int ans = LLONG_MAX;
  ans = 1 + solve(i + 1, min(prev, a[i]));
  if (prev > a[i] && a[i] < N)
    ans = min(ans, solve(i + 1, a[i]));
  else if (a[i] < N)
    ans = min(ans, a[i] - prev + solve(i + 1, a[i]));
  return dp[i][prev] = ans;
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cout << solve(0, 0) << endl;
}
