include<bits/stdc++.h>
pragma GCC optimize(1)
pragma GCC optimize(2)
pragma GCC optimize(3,"Ofast","inline")
define reg register
define int long long
using namespace std;
inline int read()
{
short f=1;
int x=0;
char c=getchar();
while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9') {x=(x<<1)+(x<<3)+(c^48);c=getchar();}
return x*f;
}
int n,a[300010],mx[300010],mn[300010],ans;
stack
signed main()
{
n=read();
for(reg int i=1;i<=n;i=-~i) a[i]=read();
maxx.push(1);minn.push(1);
for(reg int i=2;i<=n;i=-~i)
{
while(!maxx.empty()&&a[i]>=a[maxx.top()]) mx[maxx.top()]=i,maxx.pop();
while(!minn.empty()&&a[i]<a[minn.top()]) mn[minn.top()]=i,minn.pop();
maxx.push(i);minn.push(i);
}
while(!maxx.empty()) mx[maxx.top()]=n+1,maxx.pop();
while(!minn.empty()) mn[minn.top()]=n+1,minn.pop();
for(reg int l=1,r=1;r<=n;r=-~r)
{
while(mx[r]<mn[l]&&r!=mx[r]&&r<=n) r=mx[r];
ans=-ans;l=-r;
}
return printf("%lld",ans),0;
}