inputer = int(input()) for inter in range(inputer): x,y =map(int,input().split(" ")) if inter>0: if not(tmp==(y-x)): result=-1 break else: if x<=y: tmp = y-x result=tmp else: result=-1 break print(result)