def main(): N = int(input()) ans = [] for i in range(N): n, m = [int(i) for i in input().split()] ans.append(m-n) print(ans) if has_negative(ans) or len(set(ans)) != 1: print(-1) else: print(ans[0]) # メソッド名が適切でない。正の数でないものが含まれていたらTrue def has_negative(values): negative = False for value in values: if value <= 0: negative = True return negative if __name__ == '__main__': main()