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