import sequtils,strutils var N = stdin.readline.parseInt A = stdin.readline.split.map(parseInt) used : array[100010, bool] visited : array[100010,bool] ans = 0 proc dfs(p : int) = visited[p] = true var np = (p + 1) mod N if A[np] == A[p] and visited[np] == false: dfs(np) np = p - 1 if np == -1 and A[p] == A[A.high] and visited[A.high] == false: ans = 1 dfs(A.high) elif np >= 0 and A[np] == A[p] and visited[np] == false: dfs(np) for i,a in A: if visited[i]: continue if used[a]: ans = -1 break used[a] = true dfs(i) echo ans