#include <bits/stdc++.h>
using namespace std;
int n, a[5001], dp[5001][5001];
int sol(int lst, int cur) {
  if (cur == n + 1) {
    return 0;
  }
  if (dp[lst][cur] != -1) {
    return dp[lst][cur];
  }
  int ret;
  if (a[lst] <= a[cur]) {
    ret = min(sol(lst, cur + 1) + 1, sol(cur, cur + 1) + a[cur] - a[lst]);
  } else {
    ret = sol(cur, cur);
  }
  return dp[lst][cur] = ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  memset(dp, -1, sizeof(dp));
  cout << sol(0, 1);
  return 0;
}
