n = int(input()) *a, = map(int,input().split()) v = 10**10 p = [0]*n for i in range(n)[::-1]: if a[i] > v: break p[i] = 1 v = a[i] v = -1 q = [0]*n for i in range(n): if a[i] < v: break q[i] = 1 v = a[i] idx = i v = q[idx] for i in range(idx,n): if a[i] < v: break q[i] = 1 v = a[i] L,R = q[0],q[idx-1] ans = 2 for i in range(idx,n): if q[i-1] == p[i] == 1 and a[i-1] <= L and R <= a[i]: ans = 1 #print(p) #print(idx,q) if p[0] == 1: ans = 0 print(ans)