N = int(input()) S = list(map(lambda x: int(x)-1, input().split())) xs = S[:] cnt = 0 for i in range(N): if xs[i] == i: continue for j in range(i+1, N): if xs[j] == i: xs[i], xs[j] = xs[j], xs[i] cnt += 1 break if cnt % 2 == 0: print(1) else: print(-1)