N = int(input()) L = [] for _ in range(N): x, y = map(int, input().split()) if y - x < 0: print(-1) break else: L += [y - x] L = list(set(L)) print([-1, *L][len(L) == 1]) break