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