n = gets.to_i bef = -1 n.times do |i| a = gets.split.map(&:to_i) d = a[1].to_i - a[0].to_i if d <= 0 puts -1 exit else if bef == -1 bef = d end if d != bef puts -1 exit end bef = d end end puts bef