#include<bits/stdc++.h>
using namespace std;
const int maxn=2E5+5;
int n,a[maxn];
struct line
{
	int l,r,w;
	line(int a=0,int b=0,int c=0):l(a),r(b),w(c){}
	inline line operator&(const line&x){return line(max(l,x.l),min(r,x.r));}
	inline line operator^(const line&x){return l==x.l?line(r+1,x.r):line(l,x.l-1);}
	inline bool empty(){return l>r;}
	bool operator<(const line&A)const
	{
		return w<A.w;
	}
};
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	vector<line>now;
	now.push_back(line(0,0,0));
	for(int i=1;i<=n+1;++i)
	{
		int del=a[i]-a[i-1];
		line base(0,a[i]);
		vector<line>cur;
		for(auto p:now)
		{
			line x=line(0,min(p.r-1,del+p.r-1))&base;
			x.w=p.w+2;
			if(!x.empty())
				cur.push_back(x);
			
			x=line(del+p.l,p.r-1)&base;
			x.w=p.w+1;
			if(!x.empty())
				cur.push_back(x);
			
			x=line(p.l,del+p.r-1)&base;
			x.w=p.w+1;
			if(!x.empty())
				cur.push_back(x);
			
			x=line(max(p.l,del+p.l),a[i])&base;
			x.w=p.w;
			if(!x.empty())
				cur.push_back(x);
		}
		sort(cur.begin(),cur.end());
		now.clear();
		for(auto x:cur)
		{
			line g=x;
			for(auto y:now)
			{
				line tmp=g&y;
				if(!tmp.empty())
					g=g^tmp;
				if(g.empty())
					break;
			}
			g.w=x.w;
			if(!g.empty())
				now.push_back(g);
		}
	}
	cout<<now[0].w<<endl;
	return 0;
}
