import sys from sys import stdin import bisect N = int(stdin.readline()) A = list(map(int,stdin.readline().split())) B = [A[i] for i in range(N)] B.sort() while len(A) > 0 and B[-1] == A[-1]: del A[-1] del B[-1] if len(A) == 0: print (0) sys.exit() C = [ (A[i],i) for i in range(len(A)) ] C.sort() for i in range(len(A)-1): if C[i+1][1] != (C[i][1]+1) % len(C): print (2) sys.exit() print (1)