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