n = gets.to_i diff = [] n.times do a, b = gets.split.map(&:to_i) if a > b puts -1 break else diff << b - a end end puts diff.uniq.min == diff.uniq.max ? diff.first : -1