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