#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long dp[5005][5005], n, a[5005];
long long help(long long id, long long ht) {
  if (ht > 5000) return 1e9;
  if (id == n) return 0;
  if (dp[id][ht] >= 0) return dp[id][ht];
  if (ht >= a[id]) return dp[id][ht] = help(id + 1, a[id]);
  return dp[id][ht] =
             min(1 + help(id + 1, ht), a[id] - ht + help(id + 1, a[id]));
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  memset(dp, -1, sizeof(dp));
  cout << help(0, 0);
  return 0;
}
