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

from operator import itemgetter



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

ab = [list(map(int, input().split())) for _ in range(m)]

ab.sort(key=itemgetter(1,0))



cnt = 0

cb = -1

for (a,b) in ab:

    if cb == -1:

        cb = b - 1

        cnt += 1

    elif a<=cb:

        continue

    else:

        cb = b - 1

        cnt += 1



print(cnt)

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

from operator import itemgetter

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

ab = [list(map(int, input().split())) for _ in range(m)]



res = 0

ab.sort(key=itemgetter(1))



i = 0

while i<m:

    a,b = ab[i]

    for j in range(i+1,m):

        if ab[j][0]<b<=ab[j][1]:

            i += 1

        else:

            break

    i += 1

    res += 1



print(res)

# -*- coding: utf-8 -*-
from operator import itemgetter

n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
ab.sort(key=itemgetter(1, 0))
cnt = 0
cb = -1
for (a, b) in ab:
    if cb == -1:
        cb = b - 1
        cnt += 1
    elif a <= cb:
        continue
    else:
        cb = b - 1
        cnt += 1
print(cnt)

# -*- coding: utf-8 -*-
from operator import itemgetter

n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
res = 0
ab.sort(key=itemgetter(1))
i = 0
while i < m:
    a, b = ab[i]
    for j in range(i + 1, m):
        if ab[j][0] < b <= ab[j][1]:
            i += 1
        else:
            break
    i += 1
    res += 1
print(res)

-ab.sort(key=itemgetter(1, 0)) -cnt = 0 -cb = -1 -for (a, b) in ab: -    if cb == -1: -        cb = b - 1 -        cnt += 1 -    elif a <= cb: -        continue -    else: -        cb = b - 1 -        cnt += 1 -print(cnt) +res = 0 +ab.sort(key=itemgetter(1)) +i = 0 +while i < m: +    a, b = ab[i] +    for j in range(i + 1, m): +        if ab[j][0] < b <= ab[j][1]: +            i += 1 +        else: +            break +    i += 1 +    res += 1 +print(res)