gets.to_i.times.map{ a,b = gets.split.map(&:to_i); b - a}.uniq.tap{|ans| puts ans.size == 1 && ans[0] > 0 ? ans[0] : -1 }