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

AB = []

for _ in range(M):

    AB.append(list(map(int,input().split())))



AB.sort(key=lambda x:x[1])



cur = 0

ans = 0

for a,b in AB:

    if cur > a:

        continue

    

    ans += 1

    cur = b



print(ans)
import sys

stdin = sys.stdin



sys.setrecursionlimit(10**5)



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

def li_(): return [int(x)-1 for x in stdin.readline().split()]

def lf(): return list(map(float, stdin.readline().split()))

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(stdin.readline())

def nf(): return float(stdin.readline())



n,m = li()

ab = []

for _ in range(m):

    a,b = li_()

    ab.append(tuple([a,b]))

    

ab.sort(key=lambda x:x[1])

ans = 0

cur = -1



for a,b in ab:

    if a >= cur:

        ans += 1

        cur = b

        

print(ans)
N, M = list(map(int, input().split()))
AB = []
for _ in range(M):
    AB.append(list(map(int, input().split())))
AB.sort(key=lambda x: x[1])
cur = 0
ans = 0
for a, b in AB:
    if cur > a:
        continue
    ans += 1
    cur = b
print(ans)

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**5)


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


def li_():
    return [int(x) - 1 for x in stdin.readline().split()]


def lf():
    return list(map(float, stdin.readline().split()))


def ls():
    return stdin.readline().split()


def ns():
    return stdin.readline().rstrip()


def lc():
    return list(ns())


def ni():
    return int(stdin.readline())


def nf():
    return float(stdin.readline())


n, m = li()
ab = []
for _ in range(m):
    a, b = li_()
    ab.append(tuple([a, b]))
ab.sort(key=lambda x: x[1])
ans = 0
cur = -1
for a, b in ab:
    if a >= cur:
        ans += 1
        cur = b
print(ans)

-N, M = list(map(int, input().split())) -AB = [] -for _ in range(M): -    AB.append(list(map(int, input().split()))) -AB.sort(key=lambda x: x[1]) -cur = 0 +import sys + +stdin = sys.stdin +sys.setrecursionlimit(10**5) + + +def li(): +    return list(map(int, stdin.readline().split())) + + +def li_(): +    return [int(x) - 1 for x in stdin.readline().split()] + + +def lf(): +    return list(map(float, stdin.readline().split())) + + +def ls(): +    return stdin.readline().split() + + +def ns(): +    return stdin.readline().rstrip() + + +def lc(): +    return list(ns()) + + +def ni(): +    return int(stdin.readline()) + + +def nf(): +    return float(stdin.readline()) + + +n, m = li() +ab = [] +for _ in range(m): +    a, b = li_() +    ab.append(tuple([a, b])) +ab.sort(key=lambda x: x[1]) -for a, b in AB: -    if cur > a: -        continue -    ans += 1 -    cur = b +cur = -1 +for a, b in ab: +    if a >= cur: +        ans += 1 +        cur = b