n = int(input()) tmp = [] for i in range(n): x, y = map(int, input().split()) z = y - x if z > 0: tmp.append(z) ans = set(tmp) if len(ans) == 1: print(*ans) else: print(-1)