n = input() s = set() for i in range(n): a,b = map(int, raw_input().split()) s.add(b - a) l = list(s) if (len(s) == 1 and l[0] >= 1): print l[0] else: print -1