N = int(input()) S = set() for i in range(N): x, y = map(int, input().split()) if x >= y: print(-1) exit() S.add(y-x) if len(S) == 1: print(S.pop()) else: print(-1)