n = gets.to_i l = [] r = [] n.times do x, y = gets.split.map(&:to_i) l << x r << y end idx = [] (0..n - 1).each do |i| idx << i end ans = 0 idx.permutation do |id| ok = true x = 0 (0..n - 1).each do |i| if r[id[i]] < x then ok = false break end if x < l[id[i]] then x = l[id[i]] end end if ok then ans += 1 end end puts ans