#include <bits/stdc++.h>
using namespace std;

int n, u, prv = 0, lz = 0, rz = 0, lo = 0, ro = 0, ans = 0;

void process(int prv, int cur) {
    int dif = cur - prv;
    int lt = max(0, min(dif, 0) + lz);
    int rt = min(cur, max(dif, 0) + rz);
    lz = min(cur + 1, max(dif, 0) + lz);
    rz = min(cur, max(dif, 0) + rz);
    lo = min(cur + 1, max(dif, 0) + lo);
    ro = min(cur, max(dif, 0) + ro);
    lo = min(lo, lt);
    ro = max(ro, rt);
    if (lz > rz) {
        lz = lo; rz = ro;
        lo = 0; ro = cur;
        ans++;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    while (n--) {
        cin >> u;
        process(prv, u);
        prv = u;
    }
    process(prv, 0);
    cout << ans;
}
