if __name__ == '__main__': numberList=[] n=input() n=int(n) while n>0: n-=1 xy=input() x,y=xy.split(' ') numberList.append(x) numberList.append(y) ans=int(numberList[1])-int(numberList[0]) if ans<0: ans=-1 n=2 while len(numberList)>n: difference=int(numberList[n+1])-int(numberList[n]) if ans!=difference: ans=-1 break else: n+=2 print(ans)