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