N=int(input()) A=set() for _ in range(N): x,y=map(int,input().split()) A.add(y-x) A=list(A) if len(A)==1 and A[0]>0: print(A[0]) else:print(-1)