
=begin
5
1 2
3 9
3 5
5 9
6 8
=end

class Curriculum
    attr_reader :data, :start_time, :end_time, :diff

    def initialize(a)
        @data = a
        @start_time = a[0]
        @end_time = a[1]
        @diff = a[1] - a[0]
    end

    def <=>(t)
        c = 0

        self.data.size.times do |i|
            c = self.data[i] <=> t.data[i]

            if c != 0 then
                break
            end
        end

        return c
    end
end

n = gets.to_i

a = []
n.times do |i|
    a[i] = Curriculum.new(gets.split(" ").map(&:to_i))
end

a = a.sort

#p a.map{ |x| [x.start_time, x.end_time] }

i = 0
while i < a.size - 1
    if a[i].end_time >= a[i + 1].end_time then
        a.delete_at(i)
    else
        if a[i].end_time >= a[i + 1].start_time then
            a.delete_at(i + 1)
        else
            i += 1
        end
    end
end

#p a.map{ |x| [x.start_time, x.end_time] }

print a.size, "\n"
exit

def dive(now, a, c)
    if !a then
        return c
    end

    count = c

    a.size.times do |i|
        if a[i].start_time > now.end_time then
            k = dive(a[i], a[i + 1, a.size], c + 1)

            if k > count then
                count = k
            end
        end
    end

    return count
end


count = 1
max = 10
if a.size > 1000 then
  max = 1
end
max.times do |i|
    k = dive(a[i], a[i + 1, a.size], 1)
    if k > count then
        count = k
    end
end

print count, "\n"

