N=int(input()) S=set() for i in range(N): X,Y=map(int,input().split()) S.add(Y-X) O=S.pop() if len(S)>0 or O<1:O=-1 print(O)