n=int(input()) ls1=[] lsans=[] flg=0 for i in range(n): ls1=list(map(int,input().split())) lsans.append(ls1[1]-ls1[0]) if lsans[0] == int(lsans[0]):#整数判定 if lsans[0]>=0:#正判定 for i in range(2):#同値判定 if lsans[i-1]!=lsans[i]: flg=1 else: flg=1 else: flg=1 if flg==1: print(-1) else: print(lsans[0])