ary = []
gets.chomp.to_i.times do
    ary << gets.chomp.split(" ").map { |i| i.to_i }
end
ary = ary.sort_by do |a|
    a[1]
end
now = -1
count = 0
ary.each do |a|
    if a[0] > now
        count += 1
        now = a[1]
    end
end
puts count
