for i in range(int(input())): x,y=map(int,input().split()) if i and (y-x<1 or z!=y-x) : z=-1 break z=y-x print(z)