n = gets.to_i x, y = gets.split.map(&:to_i) a = y - x if a <= 0 puts -1 exit end (n-1).times do x, y = gets.split.map(&:to_i) unless y - x == a puts -1 exit end end puts a