n = gets.to_i arr = [] n.times do |i| a, b = gets.split.map(&:to_i) arr << b - a end puts arr.uniq.count == 1 && arr[0] > 0 ? arr[0] : -1