Buggy python submission (verdict: Time Limit Exceeded):
from pprint import pprint
from copy import deepcopy

#N <= 10**5なので、全探索はNG
#Greedyでいける？


n,m = map(int,input().split())

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

bridge_list = [[] for _ in range(n-1)]

for i in range(m):
    startpoint = requests[i][0]
    endpoint = requests[i][1]
    for j in range(startpoint,endpoint):
        bridge_list[j-1].append(i)

#pprint(bridge_list)

checked_requests = [0] * m

#bridge_list = sorted(bridge_list, key=lambda x: len(x))

counter = 0

while sum(checked_requests) != m:
    #max_index = bridge_list.index(max(list(map(len,bridge_list))))
    length_list = list(map(len,bridge_list))
    max_index = length_list.index(max(length_list))

    #bridge_list[max_index]を直接 for k in に突っ込むと、removeメソッドがあるため動作がおかしくなってしまう。
    temp = deepcopy(bridge_list[max_index])

    for k in temp:
        checked_requests[k] = 1
        for l in range(n-1):
            try:
                bridge_list[l].remove(k)
            except ValueError:
                pass
    
    counter += 1
    
pprint(counter)







Fixed submission:
#この方法だとTLEになるためNG

from pprint import pprint
from copy import deepcopy

#N <= 10**5なので、全探索はNG
#Greedyでいける？


n,m = map(int,input().split())

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

#区間スケジュール問題と考え、終端が小さい順で並べる。その後Greedyで計算。
requests = sorted(requests, key=lambda x:x[1])

counter = 0
before_point = -float('inf')

#pprint(requests)

for i in range(m):
    if requests[i][0] >= before_point:
        counter += 1
        before_point = requests[i][1]
        #print("requests[{}]={} YES".format(i,requests[i]))
    else:
        #print("requests[{}]={} NO".format(i,requests[i]))
        pass

print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
from pprint import pprint
from copy import deepcopy

#N <= 10**5なので、全探索はNG
#Greedyでいける？


n,m = map(int,input().split())

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

bridge_list = [[] for _ in range(n-1)]

for i in range(m):
    startpoint = requests[i][0]
    endpoint = requests[i][1]
    for j in range(startpoint,endpoint):
        bridge_list[j-1].append(i)

#pprint(bridge_list)

checked_requests = [0] * m

#bridge_list = sorted(bridge_list, key=lambda x: len(x))

counter = 0

while sum(checked_requests) != m:
    #max_index = bridge_list.index(max(list(map(len,bridge_list))))
    length_list = list(map(len,bridge_list))
    max_index = length_list.index(max(length_list))

    #bridge_list[max_index]を直接 for k in に突っ込むと、removeメソッドがあるため動作がおかしくなってしまう。
    temp = deepcopy(bridge_list[max_index])

    for k in temp:
        checked_requests[k] = 1
        for l in range(n-1):
            try:
                bridge_list[l].remove(k)
            except ValueError:
                pass
    
    counter += 1
    
pprint(counter)







Fixed submission:
#この方法だとTLEになるためNG

from pprint import pprint
from copy import deepcopy

#N <= 10**5なので、全探索はNG
#Greedyでいける？


n,m = map(int,input().split())

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

#区間スケジュール問題と考え、終端が小さい順で並べる。その後Greedyで計算。
requests = sorted(requests, key=lambda x:x[1])

counter = 0
before_point = -float('inf')

#pprint(requests)

for i in range(m):
    if requests[i][0] >= before_point:
        counter += 1
        before_point = requests[i][1]
        #print("requests[{}]={} YES".format(i,requests[i]))
    else:
        #print("requests[{}]={} NO".format(i,requests[i]))
        pass

print(counter)