I=input l=[] n=int(I()) for i in '.'*n:a,b=map(int,input().split());l+=[b-a] print(b-a if len(set(l))<2 else -1)