#include <bits/stdc++.h>
using namespace std;
const int N = 5001;
int read() {
  int c, x = 0;
  while (!isdigit(c = getchar()))
    ;
  while (x = x * 10 + c - '0', isdigit(c = getchar()))
    ;
  return x;
}
int h[N], f[N][N];
int main() {
  int n = read(), ans = 0;
  for (int i = 1; i <= n; ++i) {
    h[i] = read();
    if (h[i] >= n) --i, --n, ++ans;
  }
  for (int i = 1; i <= n; ++i) {
    int val = 2e9;
    for (int j = 0; j <= h[i]; ++j) {
      if (j <= h[i - 1]) val = min(f[i - 1][j] - j, val);
      if (j < h[i])
        f[i][j] = val + j + 1;
      else
        f[i][j] = val + j;
    }
    for (int j = h[i] - 1; j >= 0; --j) f[i][j] = min(f[i][j + 1], f[i][j]);
  }
  int val = 2e9;
  for (int i = 0; i <= h[n]; ++i) val = min(f[n][i], val);
  printf("%d", val + ans);
  return 0;
}
