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