mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) AA = [] prev = -1 for a in A: if a != prev: AA.append(a) prev = a seen = [0] * (N+1) for i in range(len(AA)-1): a = AA[i] if seen[a]: print(-1) exit() seen[a] = 1 if seen[AA[-1]]: print(1) else: print(0) if __name__ == '__main__': main()