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