#include using namespace std; //#define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' #define vec vector #define mat vector > #define fi first #define se second #define double long double typedef long long ll; typedef unsigned long long ull; typedef pair pll; //typedef long double ld; typedef complex Complex; const ll INF=1e9+7; const ll MOD=998244353; const ll inf=INF; const ll mod=INF; const ll MAX=200010; signed main(){ ll n;cin>>n; vectorb(n); rep(i,n)cin>>b[i]; vectorm(n); m[0]=b[0]; REP(i,1,n){ m[i]=max(m[i],b[i]); m[i]=max(m[i],m[i-1]); } vectora(0); ll la=n; for(int i=n-1;i>=1;i--){ if(m[i-1]>b[i]){ break; } la--; } rep(i,la){ a.pb(b[i]); } rep(i,la){ a.pb(a[i]); } ll cnt=1; ll ma=1; REP(i,1,2*la){ if(a[i]>=a[i-1]){ cnt++; }else{ ma=max(ma,cnt); cnt=1; } } ma=max(ma,cnt); bool f=1; REP(i,1,n){ if(b[i-1]>b[i])f=0; } if(f){ cout<<0<=la){ cout<<1<