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