import sys

from collections import defaultdict

input = sys.stdin.readline





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

path = defaultdict(list)



for _ in range(m):

    a, b = list(map(int, input().split()))

    path[a].append(b)



idx = 1

ans = 1

right = n

while idx <= n:

    candidate = path[idx]

    if not candidate:

        idx += 1

        continue

    if right <= idx:

        ans += 1

        right = n

    cut = min(candidate)

    right = min(right, cut)

    idx += 1



print(ans)
import sys

input = sys.stdin.readline

INF = float('INF')



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

path = [INF]*(n+1)



for _ in range(m):

    a, b = list(map(int, input().split()))

    path[a] = min(path[a], b)



left = 1

ans = 1

right = n

while left <= n:

    cut = path[left]

    if cut == INF:

        left += 1

        continue

    if right <= left:

        ans += 1

        right = n

    right = min(right, cut)

    left += 1



print(ans)
import sys
from collections import defaultdict

input = sys.stdin.readline
n, m = list(map(int, input().split()))
path = defaultdict(list)
for _ in range(m):
    a, b = list(map(int, input().split()))
    path[a].append(b)
idx = 1
ans = 1
right = n
while idx <= n:
    candidate = path[idx]
    if not candidate:
        idx += 1
        continue
    if right <= idx:
        ans += 1
        right = n
    cut = min(candidate)
    right = min(right, cut)
    idx += 1
print(ans)

import sys

input = sys.stdin.readline
INF = float("INF")
n, m = list(map(int, input().split()))
path = [INF] * (n + 1)
for _ in range(m):
    a, b = list(map(int, input().split()))
    path[a] = min(path[a], b)
left = 1
ans = 1
right = n
while left <= n:
    cut = path[left]
    if cut == INF:
        left += 1
        continue
    if right <= left:
        ans += 1
        right = n
    right = min(right, cut)
    left += 1
print(ans)

-from collections import defaultdict +INF = float("INF") -path = defaultdict(list) +path = [INF] * (n + 1) -    path[a].append(b) -idx = 1 +    path[a] = min(path[a], b) +left = 1 -while idx <= n: -    candidate = path[idx] -    if not candidate: -        idx += 1 +while left <= n: +    cut = path[left] +    if cut == INF: +        left += 1 -    if right <= idx: +    if right <= left: -    cut = min(candidate) -    idx += 1 +    left += 1