#include <bits/stdc++.h>
using namespace std;
int dp[5050][5050] = {};
int main() {
  int n;
  cin >> n;
  int h[6000] = {};
  for (int i = 1; i <= n; i++) cin >> h[i];
  for (int i = 1; i < h[1] && i <= 5000; i++) dp[1][i] = i + 1;
  if (h[1] <= 5000) dp[1][h[1]] = h[1];
  dp[1][0] = 1;
  for (int i = 2; i <= n; i++) {
    if (h[i - 1] >= h[i]) {
      for (int j = 0; j < h[i] && j <= 5000; j++) dp[i][j] = dp[i - 1][j] + 1;
      if (h[i] <= 5000) {
        int mmin = 5000;
        for (int j = h[i]; j <= h[i - 1] && j <= 5000; j++)
          if (dp[i - 1][j] != 0) mmin = min(mmin, dp[i - 1][j]);
        dp[i][h[i]] = mmin;
      }
    } else {
      for (int j = 0; j <= h[i - 1] && j <= 5000; j++)
        dp[i][j] = dp[i - 1][j] + 1;
      for (int j = h[i - 1] + 1; j < h[i] && j <= 5000; j++)
        dp[i][j] = dp[i - 1][h[i - 1]] + j - h[i - 1] + 1;
      if (h[i] <= 5000) dp[i][h[i]] = dp[i - 1][h[i - 1]] + h[i] - h[i - 1];
    }
    int mmin = 5000;
    for (int j = 0; j <= h[i - 1] && j <= 5000; j++)
      if (dp[i - 1][j] != 0) mmin = min(mmin, dp[i - 1][j]);
    dp[i][0] = min(dp[i][0], mmin + 1);
  }
  int mmin = 5000;
  for (int j = 0; j <= h[n] && j <= 5000; j++)
    if (dp[n][j] != 0) mmin = min(mmin, dp[n][j]);
  cout << mmin << endl;
  return 0;
}
