N = int(input().strip()) lst = [] for _ in range(N): X, Y = [int(i) for i in input().strip().split(' ')] lst.append(Y - X) print(str(max(lst) if max(lst) > 0 and max(lst) == min(lst) else -1))