n= int(input()) for i in range(n): a,b = map(int,input().split()) c = b - a if i > 0: if test!=c: print(-1) exit() test = c if c>0: print(c) else: print(-1)