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