#include <bits/stdc++.h>
using namespace std;
int dp[5001][5001];
int a[5001];
int main() {
  int n;
  while (cin >> n) {
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 0; i <= n; i++) dp[n][i] = 0;
    for (int i = n; i > 0; i--) {
      for (int j = 0; j < i; j++) {
        if (a[j] >= a[i])
          dp[i - 1][j] = dp[i][i];
        else
          dp[i - 1][j] = min(dp[i][j] + 1, dp[i][i] + a[i] - a[j]);
      }
    }
    cout << dp[0][0] << endl;
  }
}
