N = int(input())
S = map(int, input().split())
S = [i - 1 for i in S]

cnt = 0
for i in range(N):
    now = S[i]
    while now != i:
        cnt += 1
        S[i], S[now] = S[now], S[i]
        now = S[i]

if cnt % 2 == 0:
    print(1)
else:
    print(-1)