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



lst = []

for i in range(M):

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

    lst += [a[::-1]]



lst.sort()



count = 0

position = 0



for i in range(M):

    if position <= lst[i][1]:

        count += 1

        position = lst[i][0]

        

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



AB = [list(map(int, input().split())) for _ in range(M)]



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



MAX = 10 ** 9



count = 1

min_ = MAX

for a, b in AB:

    if a < min_:

        min_ = min(min_, b)

    else:

        count += 1

        min_ = b



print (count)

N, M = list(map(int, input().split()))
lst = []
for i in range(M):
    a = list(map(int, input().split()))
    lst += [a[::-1]]
lst.sort()
count = 0
position = 0
for i in range(M):
    if position <= lst[i][1]:
        count += 1
        position = lst[i][0]
print(count)

N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
AB.sort(key=lambda x: x[0])
MAX = 10**9
count = 1
min_ = MAX
for a, b in AB:
    if a < min_:
        min_ = min(min_, b)
    else:
        count += 1
        min_ = b
print(count)

-lst = [] -for i in range(M): -    a = list(map(int, input().split())) -    lst += [a[::-1]] -lst.sort() -count = 0 -position = 0 -for i in range(M): -    if position <= lst[i][1]: +AB = [list(map(int, input().split())) for _ in range(M)] +AB.sort(key=lambda x: x[0]) +MAX = 10**9 +count = 1 +min_ = MAX +for a, b in AB: +    if a < min_: +        min_ = min(min_, b) +    else: -        position = lst[i][0] +        min_ = b