n = int(input()) s = set() for i in range(n): x, y = map(int, input().split()) s.add(y-x) s = list(s) if len(s) == 1 and s[0] > 0: print(s[0]) else: print(-1)