class Problem0185: def solve(this): n = int(input()) c = True res = set() for i in range(n): x, y = map(int, input().split()) if x >= y: c = False res.add(y - x) if c and len(res) == 1: t = list(res) print(t[0]) else: print(-1) if __name__ == "__main__": problem = Problem0185() problem.solve()