#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
const int maxn = 300010;
int n, a[maxn], res;
ll dp[3]{0, INT_MAX, INT_MAX}, tmp[9];
void update(int dh, int h){
	fill(tmp, tmp+9, INT_MAX);
	if(dh > 0){
		for(int i = 0;i < 3;++i)
			tmp[i] = dp[i] + dh;
		for(int i = 1;i < 3;++i)
			tmp[i-1] = min(tmp[i-1], dp[i]);
		int p = 0;
		if(dp[2] == INT_MAX)++p, ++res;

		for(int i = 1;i < 3;++i)
			dp[i] = tmp[i - p];
	}
	else{
		for(int i = 0;i < 3;++i)
			tmp[i] = dp[i];
		for(int i = 1;i < 3;++i)
			tmp[i-1] = min(tmp[i-1], max(0ll, dp[i] + dh));
		for(int i = 0;i < 3;++i)
			dp[i] = tmp[i];
		for(int i = 0;i < 3;++i)
			if(dp[i] > h)dp[i] = INT_MAX;
	}
	return;
	for(int i = 0;i < 3;++i)
		cout << dp[i] << " \n"[i == 2];
}
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for(int i = 1;i <= n;++i)
		cin >> a[i];
	for(int i = 1;i <= n+1;++i)if(a[i] != a[i-1])
		update(a[i]-a[i-1], a[i]);
	for(int i = 1;i < 3;++i)if(dp[i] != INT_MAX)
		--res;
	cout << res << '\n';
}

