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

request=[]

for _ in range(M):

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

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

    

memory=request[0][1]

head = request[0][0]

index = 0

ans = 0



def equal():

    if index == M-1: return False

    else: return head == request[index+1][0]



while head <= N:

    if head == memory:

        ans +=1

        memory = N+1

    elif equal():

        index +=1

        memory=min(request[index][1],memory)

    else: head +=1

        

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

AB=[]

for _ in range(M):

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

    

request_max=0

request_num=0



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

for (a,b) in AB:

    if a>=request_max:

        request_num +=1

        request_max = b

print(request_num)
N, M = list(map(int, input().split()))
request = []
for _ in range(M):
    request.append(list(map(int, input().split())))
request.sort(key=lambda x: x[0])
memory = request[0][1]
head = request[0][0]
index = 0
ans = 0


def equal():
    if index == M - 1:
        return False
    else:
        return head == request[index + 1][0]


while head <= N:
    if head == memory:
        ans += 1
        memory = N + 1
    elif equal():
        index += 1
        memory = min(request[index][1], memory)
    else:
        head += 1
print(ans)

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

-request = [] +AB = [] -    request.append(list(map(int, input().split()))) -request.sort(key=lambda x: x[0]) -memory = request[0][1] -head = request[0][0] -index = 0 -ans = 0 - - -def equal(): -    if index == M - 1: -        return False -    else: -        return head == request[index + 1][0] - - -while head <= N: -    if head == memory: -        ans += 1 -        memory = N + 1 -    elif equal(): -        index += 1 -        memory = min(request[index][1], memory) -    else: -        head += 1 -print(ans) +    AB.append(tuple(map(int, input().split()))) +request_max = 0 +request_num = 0 +AB.sort(key=lambda x: x[1]) +for (a, b) in AB: +    if a >= request_max: +        request_num += 1 +        request_max = b +print(request_num)