import sys

from operator import itemgetter

readline = sys.stdin.readline

readlines = sys.stdin.readlines



N, M = list(map(int, readline().split()))

ab = [tuple(map(int, i.split())) for i in readlines()]



ab.sort(key=itemgetter(1))

right_island = ab[0][1]

answer = 1



for i, j in ab:

    if i >= right_island:

        answer += 1

        right_island = j



print(answer)
import sys

from operator import itemgetter

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines



N, M = list(map(int, readline().split()))

ab = list(map(int, read().split()))

ab = sorted(zip(ab, ab), key=itemgetter(1))



right_island = ab[0][1]

answer = 1



for i, j in ab:

    if i >= right_island:

        answer += 1

        right_island = j



print(answer)
import sys
from operator import itemgetter

readline = sys.stdin.readline
readlines = sys.stdin.readlines
N, M = list(map(int, readline().split()))
ab = [tuple(map(int, i.split())) for i in readlines()]
ab.sort(key=itemgetter(1))
right_island = ab[0][1]
answer = 1
for i, j in ab:
    if i >= right_island:
        answer += 1
        right_island = j
print(answer)

import sys
from operator import itemgetter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
N, M = list(map(int, readline().split()))
ab = list(map(int, read().split()))
ab = sorted(zip(ab, ab), key=itemgetter(1))
right_island = ab[0][1]
answer = 1
for i, j in ab:
    if i >= right_island:
        answer += 1
        right_island = j
print(answer)

+read = sys.stdin.read -ab = [tuple(map(int, i.split())) for i in readlines()] -ab.sort(key=itemgetter(1)) +ab = list(map(int, read().split())) +ab = sorted(zip(ab, ab), key=itemgetter(1))