N = int(input()) A = list(map(int, input().split())) l = 0 r = 0 cnt = 0 for i,a in enumerate(A,start=1): if l==0 and i!=a: l=i if r==0 and N