def main(): import sys input=sys.stdin.readline n=int(input()) a=list(map(int,input().split())) r=[False]*(n-1)+[True] for i in range(n-2,-1,-1): r[i]=r[i+1]and(a[i]<=a[i+1]) l=[0]*n for i in range(1,n): l[i]=l[i-1]+(a[i-1]>a[i]) Max=a[0] for i in range(1,n): if l[i-1]==1and Max<=a[i]and a[i-1]<=a[0]and r[i]: print(1) exit(0) if Max