#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

const int INF = 1e9 + 5;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> A(N + 2, 0);

    for (int i = 1; i <= N; i++)
        cin >> A[i];

    map<int, int> dp = {{0, 0}};

    for (int i = 0; i <= N; i++) {
        map<int, int> next_dp;

        for (auto &p : dp) {
            int x1 = p.first, dp_x1 = p.second;
            int y1 = A[i] - x1;

            auto &&attempt = [&](int x2) {
                if (0 <= x2 && x2 <= A[i + 1]) {
                    int y2 = A[i + 1] - x2;
                    int value = dp_x1 + (x1 > x2 ? 1 : 0) + (y1 < y2 ? 1 : 0);
                    int previous = next_dp.find(x2) == next_dp.end() ? INF : next_dp[x2];
                    next_dp[x2] = min(previous, value);
                }
            };

            // Interesting x2 values: 0, x1 (leads to x1 == x2), A[i + 1] - y1 (leads to y1 == y2)
            attempt(0);
            attempt(x1);
            attempt(A[i + 1] - y1);

            // for (int x2 = 0; x2 <= A[i + 1]; x2++) {
            //     int y2 = A[i + 1] - x2;
            //     next_dp[x2] = min(next_dp[x2], dp[x1] + (x1 > x2 ? 1 : 0) + (y1 < y2 ? 1 : 0));
            // }
        }

        int minimum = INF;
        auto it = next_dp.begin();

        while (it != next_dp.end())
            if (it->second >= minimum) {
                it = next_dp.erase(it);
            } else {
                minimum = min(minimum, it->second);
                it++;
            }

        dp = next_dp;
    }

    cout << dp[0] << '\n';
}
