N = int(input()) D = [[int(x) for x in input().split()] for _ in range(N)] # print(D) results = [d[1]-d[0] for d in D] if len(set(results)) == 1 and results[0] > 0: print(results[0]) else: print(-1)