n=int(input()) for i in range(n): x,y = map(int,input().split()) if i == 0: t = y-x continue if y-x != t: print(-1) exit() t = y-x if t < 1: print(-1) else: print(t)