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)
# Input

import sys

stdin = sys.stdin



sys.setrecursionlimit(10 ** 7)



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):

    ai, bi = li_()

    ab.append((ai, bi))



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



ans = 0

cur = -1

for ai, bi in ab:

    if ai >= cur:

        ans += 1

        cur = bi



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)

# Input
import sys

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


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):
    ai, bi = li_()
    ab.append((ai, bi))
ab.sort(key=lambda x: x[1])
ans = 0
cur = -1
for ai, bi in ab:
    if ai >= cur:
        ans += 1
        cur = bi
print(ans)

+# Input -sys.setrecursionlimit(10**5) +sys.setrecursionlimit(10**7) -    a, b = li_() -    ab.append(tuple([a, b])) +    ai, bi = li_() +    ab.append((ai, bi)) -for a, b in ab: -    if a >= cur: +for ai, bi in ab: +    if ai >= cur: -        cur = b +        cur = bi