n = gets.chomp.to_i ans = [] for i in 0...n x, y = gets.chomp.split.map(&:to_i) ans.push y - x end puts ans.group_by{ |e| e }.values.length == 1 ? ans[0] : -1