A=set([int(y)-int(x) for x,y in [input().split() for i in '1'*int(input())]]) x=A.pop() print((-1,x)[A==set() and x>0])