# -*- coding: utf-8 -*-

import sys

n, m = list(map(int, input().split()))

ary = [tuple(map(int, line.strip().split())) for line in sys.stdin.readlines()]



demands = sorted(ary, key=lambda x: x[1])[::-1]

compressed = []

while demands:

    a, b = demands.pop()



    for i, (ai, bi) in enumerate(compressed):

        if bi <= a:

            continue



        else:

            if ai < a:

                compressed[i] = (a, min(b, bi))

            break



    else:

        compressed.append((a, b))



print((len(compressed)))

# -*- coding: utf-8 -*-

import sys

n, m = list(map(int, input().split()))

demands = [

    tuple(map(int,

              line.strip().split())) for line in sys.stdin.readlines()

]

demands.sort(key=lambda demand: demand[1])



bridge = -1

cnt = 0

for ai, bi in demands:



    if ai <= bridge:

        continue



    else:

        bridge = bi - 1

        cnt += 1



print(cnt)

# -*- coding: utf-8 -*-
import sys

n, m = list(map(int, input().split()))
ary = [tuple(map(int, line.strip().split())) for line in sys.stdin.readlines()]
demands = sorted(ary, key=lambda x: x[1])[::-1]
compressed = []
while demands:
    a, b = demands.pop()
    for i, (ai, bi) in enumerate(compressed):
        if bi <= a:
            continue
        else:
            if ai < a:
                compressed[i] = (a, min(b, bi))
            break
    else:
        compressed.append((a, b))
print((len(compressed)))

# -*- coding: utf-8 -*-
import sys

n, m = list(map(int, input().split()))
demands = [tuple(map(int, line.strip().split())) for line in sys.stdin.readlines()]
demands.sort(key=lambda demand: demand[1])
bridge = -1
cnt = 0
for ai, bi in demands:
    if ai <= bridge:
        continue
    else:
        bridge = bi - 1
        cnt += 1
print(cnt)

-ary = [tuple(map(int, line.strip().split())) for line in sys.stdin.readlines()] -demands = sorted(ary, key=lambda x: x[1])[::-1] -compressed = [] -while demands: -    a, b = demands.pop() -    for i, (ai, bi) in enumerate(compressed): -        if bi <= a: -            continue -        else: -            if ai < a: -                compressed[i] = (a, min(b, bi)) -            break +demands = [tuple(map(int, line.strip().split())) for line in sys.stdin.readlines()] +demands.sort(key=lambda demand: demand[1]) +bridge = -1 +cnt = 0 +for ai, bi in demands: +    if ai <= bridge: +        continue -        compressed.append((a, b)) -print((len(compressed))) +        bridge = bi - 1 +        cnt += 1 +print(cnt)