n=int(input()) a=list(map(int,input().split())) c=[] for i in range(n): c.append((a[i],i)) c.sort() b=[0]*n for i in range(n): b[c[i][1]]=i ans=0 pointer=0 if b[n-1]!=n-1: ans+=1 for i in range(n-2,-1,-1): if pointer>=i: break if b[i]+1!=b[i+1]: if b[i+1]==pointer: pointer+=1 else: ans+=1 print(min(2,ans))