n = int(input()) l = [] for _ in range(n): a, b = map(int, input().split()) if b - a < 0: print(-1) exit() else: l.append(b - a) l = set(l) print([-1, *l][len(l) == 1])