n = int(input()) a = list(map(int, input().split())) i = 1 while i < n and a[i-1] <= a[i]: i += 1 if i == n: print(0) exit() mx = a[i-1] i += 1 while i < n and a[i-1] <= a[i] and a[i] <= a[0]: i += 1 if i < n and a[i] < mx: print(2) exit() i += 1 while i < n and a[i-1] <= a[i]: i += 1 if i >= n: print(1) else: print(2)