t=[] for _ in '1'*int(input()): x, y = map(int,input().split()) t.append(y-x if y-x>0 else -1) print(max(t[0], -1) if len(set(t))==1 else -1)