n = int(input()) c = [] for i in range(n): x,y = map(int,input().split()) c.append(y-x) if min(c) < 1 or len(set(c)) > 1: c[0] = -1 print(c[0])