#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 200200;
ll a[N];
ll dp[N];
int n;
int ans;

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	ll lst = 0;
	for (int i = 0; i < n; i++) {
		ll x;
		scanf("%lld", &x);
		a[i] = x - lst;
		lst = x;
	}
	a[n++] = -lst;
	
	ans = 0;
	ll mx = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == 0) continue;
		if (a[i] > 0) {
			mx += a[i];
			for (int p = ans; p <= ans + 2; p++) {
				dp[p + 1] = max(dp[p + 1], dp[p] + a[i]);
			}
			dp[ans + 2] = mx;
		} else {
			for (int p = ans + 2; p > ans; p--)
				dp[p] = max(dp[p] + a[i], dp[p - 1]);
			dp[ans] += a[i];
			mx += a[i];
			for (int p = ans; p <= ans + 2; p++)
				dp[p] = min(dp[p], mx);
			while(dp[ans] < 0) {
				ans++;
				dp[ans + 2] = mx;
			}
		}
	}
	printf("%d\n", ans);

	return 0;
}
