n = int(input()) l = [] for _ in range(n): a, b = map(int, input().split()) l.append(b - a) if min(l) < 1 or len(set(l)) > 1: l[0] = -1 print(l[0])