N = int(input()) A = list(map(int, input().split())) d = {} prev = '' for a in A: if prev != a: d.setdefault(a, 0) d[a] += 1 t = len(i for i in d.values() if i >= 2) if t >= 2: print(-1) elif t >= 1: print(1) else: print(0)