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