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