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

List=[]

for i in range(b):

  p,q=list(map(int,input().split()))

  List.append([p,q])

List=sorted(List,key=lambda x:x[1])

ans=0

l=1

for i in range(b):

  if List[i][0]>=l:

    ans+=1

    l=List[i][1]

print(ans)
import math

import sys

from collections import deque

import copy

import itertools

from itertools import permutations

def mi() : return list(map(int,sys.stdin.readline().split()))

def ii() : return int(sys.stdin.readline().rstrip())

a,b=mi()

l=[list(mi()) for _ in range(b)]

l=sorted(l,key=lambda x:x[1])

q=deque([1,1])

ans=0

for i,j in l:

  y=q.pop()

  x=q.pop()

  if i<x:

    q.append(x)

    q.append(y)

  else:

    ans+=1

    q.append(j)

    q.append(j)

print(ans)

a, b = list(map(int, input().split()))
List = []
for i in range(b):
    p, q = list(map(int, input().split()))
    List.append([p, q])
List = sorted(List, key=lambda x: x[1])
ans = 0
l = 1
for i in range(b):
    if List[i][0] >= l:
        ans += 1
        l = List[i][1]
print(ans)

import math
import sys
from collections import deque
import copy
import itertools
from itertools import permutations


def mi():
    return list(map(int, sys.stdin.readline().split()))


def ii():
    return int(sys.stdin.readline().rstrip())


a, b = mi()
l = [list(mi()) for _ in range(b)]
l = sorted(l, key=lambda x: x[1])
q = deque([1, 1])
ans = 0
for i, j in l:
    y = q.pop()
    x = q.pop()
    if i < x:
        q.append(x)
        q.append(y)
    else:
        ans += 1
        q.append(j)
        q.append(j)
print(ans)

-a, b = list(map(int, input().split())) -List = [] -for i in range(b): -    p, q = list(map(int, input().split())) -    List.append([p, q]) -List = sorted(List, key=lambda x: x[1]) +import math +import sys +from collections import deque +import copy +import itertools +from itertools import permutations + + +def mi(): +    return list(map(int, sys.stdin.readline().split())) + + +def ii(): +    return int(sys.stdin.readline().rstrip()) + + +a, b = mi() +l = [list(mi()) for _ in range(b)] +l = sorted(l, key=lambda x: x[1]) +q = deque([1, 1]) -l = 1 -for i in range(b): -    if List[i][0] >= l: +for i, j in l: +    y = q.pop() +    x = q.pop() +    if i < x: +        q.append(x) +        q.append(y) +    else: -        l = List[i][1] +        q.append(j) +        q.append(j)