n=gets.to_i x,y=gets.split.map(&:to_i) ans=y-x (n-1).times do x,y=gets.split.map(&:to_i) if y-x!=ans ans = -1 break end end puts ans>0 ? ans: -1