sortsecond = lambda val: val[1]

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

l=[]

for i in range(M):

    t=input().split()

    l.append((int(t[0]),int(t[1])))

l.sort(key=sortsecond)

ans = int(0)

count = int(0)

br = int(0)





for i in range(M):

    if br<l[i][0]+1:

        count +=1

        br = l[i][1]



ans = count

print(ans)
def examD():

    N, M = LI()

    right = defaultdict(int)

    for _ in range(M):

        a, b = LI()

        right[b] = max(right[b],a)

    ans = 0; cur = 0

    for i in range(1,N+1):

        if right[i]>cur:

            ans +=1

            cur = i-1

    print(ans)



import sys,copy,bisect,itertools,heapq,math

from heapq import heappop,heappush,heapify

from collections import Counter,defaultdict,deque

def I(): return int(sys.stdin.readline())

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

def LSI(): return list(map(str,sys.stdin.readline().split()))

def LS(): return sys.stdin.readline().split()

def SI(): return sys.stdin.readline().strip()

mod = 10**9 + 7

inf = float('inf')



examD()

sortsecond = lambda val: val[1]
N, M = list(map(int, input().split()))
l = []
for i in range(M):
    t = input().split()
    l.append((int(t[0]), int(t[1])))
l.sort(key=sortsecond)
ans = int(0)
count = int(0)
br = int(0)
for i in range(M):
    if br < l[i][0] + 1:
        count += 1
        br = l[i][1]
ans = count
print(ans)

def examD():
    N, M = LI()
    right = defaultdict(int)
    for _ in range(M):
        a, b = LI()
        right[b] = max(right[b], a)
    ans = 0
    cur = 0
    for i in range(1, N + 1):
        if right[i] > cur:
            ans += 1
            cur = i - 1
    print(ans)


import sys, copy, bisect, itertools, heapq, math
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque


def I():
    return int(sys.stdin.readline())


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


def LSI():
    return list(map(str, sys.stdin.readline().split()))


def LS():
    return sys.stdin.readline().split()


def SI():
    return sys.stdin.readline().strip()


mod = 10**9 + 7
inf = float("inf")
examD()

-sortsecond = lambda val: val[1] -N, M = list(map(int, input().split())) -l = [] -for i in range(M): -    t = input().split() -    l.append((int(t[0]), int(t[1]))) -l.sort(key=sortsecond) -ans = int(0) -count = int(0) -br = int(0) -for i in range(M): -    if br < l[i][0] + 1: -        count += 1 -        br = l[i][1] -ans = count -print(ans) +def examD(): +    N, M = LI() +    right = defaultdict(int) +    for _ in range(M): +        a, b = LI() +        right[b] = max(right[b], a) +    ans = 0 +    cur = 0 +    for i in range(1, N + 1): +        if right[i] > cur: +            ans += 1 +            cur = i - 1 +    print(ans) + + +import sys, copy, bisect, itertools, heapq, math +from heapq import heappop, heappush, heapify +from collections import Counter, defaultdict, deque + + +def I(): +    return int(sys.stdin.readline()) + + +def LI(): +    return list(map(int, sys.stdin.readline().split())) + + +def LSI(): +    return list(map(str, sys.stdin.readline().split())) + + +def LS(): +    return sys.stdin.readline().split() + + +def SI(): +    return sys.stdin.readline().strip() + + +mod = 10**9 + 7 +inf = float("inf") +examD()