#include <bits/stdc++.h>
using namespace std;
int minimum(int x, int y) {
  if (x > y)
    return y;
  else
    return x;
}
int f(int n, int a[]) {
  int i, j, min, m = 0;
  min = a[0];
  for (i = 0; i < n; i++) {
    if (a[i] == 0) {
      if (i != n - 1) {
        int a1[n - i - 1];
        for (j = 0; j < n - i - 1; j++) {
          a1[j] = a[i + j + 1];
        }
        m = m + f(j, a1);
      }
      break;
    } else {
      if (min > a[i]) min = a[i];
    }
  }
  if (min != 0) {
    if (min > i)
      return m + i;
    else {
      int a2[i];
      for (j = 0; j < i; j++) {
        a2[j] = a[j] - min;
      }
      m = m + minimum(i, min + f(i, a2));
    }
  }
  return m;
}
int main() {
  int n;
  cin >> n;
  int h[n];
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  int cnt = 0;
  cnt = f(n, h);
  cout << cnt << endl;
  return 0;
}
