Buggy python submission (verdict: Time Limit Exceeded):

from operator import itemgetter
 
n,m=map(int, input().split())
A=[]
B=[]
a=0
b=0
for i in range(m):
  a,b=map(int, input().split())
  A.append([a,b])

A.sort(key=itemgetter(1))
bri=[1 for i in range(n)] #bri[0]は1,2番目の島をつなぐ

count=0

for i in range(m):
  a=A[i][0]
  b=A[i][1]
  
  if not 0 in bri[a-1:b-1]:
    bri[b-2]=0
    count+=1

print(count)


Fixed submission:

from operator import itemgetter
 
n,m=map(int, input().split())
A=[]
B=[]
a=0
b=0
for i in range(m):
  a,b=map(int, input().split())
  A.append([a,b])

A.sort(key=itemgetter(1))
bri=0 #取った橋のうち番号最大の島のもの。bri=5なら4,5番目の島の橋

count=0

for i in range(m):
  a=A[i][0]
  b=A[i][1]
  
  if a>=bri:
    bri=b
    count+=1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):

from operator import itemgetter
 
n,m=map(int, input().split())
A=[]
a=0
b=0
for i in range(m):
  a,b=map(int, input().split())
  A.append([a,b])

A.sort(key=itemgetter(1))
bri=[1 for i in range(n)] #bri[0]は1,2番目の島をつなぐ

count=0

#print(A)
for i in range(m):
  #print(i)
  a=A[i][0]
  b=A[i][1]
  #print(bri[a-1:b-1])

  if not 0 in bri[a-1:b-1]:



    #print(bri[a-1:b-1])
    bri[b-2]=0
    #print(bri)
    #print(A[i])
    #print(A)
    #print(bri)
    count+=1

print(count)


Fixed submission:

from operator import itemgetter
 
n,m=map(int, input().split())
A=[]
B=[]
a=0
b=0
for i in range(m):
  a,b=map(int, input().split())
  A.append([a,b])

A.sort(key=itemgetter(1))
bri=0 #取った橋のうち番号最大の島のもの。bri=5なら4,5番目の島の橋

count=0

for i in range(m):
  a=A[i][0]
  b=A[i][1]
  
  if a>=bri:
    bri=b
    count+=1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):

from operator import itemgetter
 
n,m=map(int, input().split())
A=[]
a=0
b=0
for i in range(m):
  a,b=map(int, input().split())
  A.append([a,b])

A.sort(key=itemgetter(1))
bri=[1 for i in range(n)] #bri[0]は1,2番目の島をつなぐ

count=0

#print(A)
for i in range(m):
  #print(i)
  a=A[i][0]
  b=A[i][1]
  #print(bri[a-1:b-1])

  zero=0
  for j in range(a-1,b-1):
    if bri[j]==0:
      zero=1
      
  if zero==0:


    #print(bri[a-1:b-1])
    bri[b-2]=0
    #print(bri)
    #print(A[i])
    #print(A)
    #print(bri)
    count+=1

print(count)


Fixed submission:

from operator import itemgetter
 
n,m=map(int, input().split())
A=[]
B=[]
a=0
b=0
for i in range(m):
  a,b=map(int, input().split())
  A.append([a,b])

A.sort(key=itemgetter(1))
bri=0 #取った橋のうち番号最大の島のもの。bri=5なら4,5番目の島の橋

count=0

for i in range(m):
  a=A[i][0]
  b=A[i][1]
  
  if a>=bri:
    bri=b
    count+=1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):

n,m=map(int, input().split())
A=[]
a=0
b=0
for i in range(m):
  a,b=map(int, input().split())
  A.append([a,b])

AA=[]
for i in range(n):
  for j in range(m):
    if A[j][0]==i :
      AA.append([A[j][0],A[j][1]])

A=AA
def kyotu(J,K):
  aa,bb=max(J[0],K[0]),min(J[1],K[1])
  if aa>=bb:
    return 0
  else:
    return [aa,bb]


kyo=[]
kk=[]
def kyotu2(k):
  for i in range(len(kyo)):
    kk=kyotu(kyo[i],A[k])
    
    if kk!=0:
      kyo[i][0]=kk[0]
      kyo[i][1]=kk[1]
      return 0
    
  kyo.append([A[k][0],A[k][1]])



for i in range(m):
  kyotu2(i)
#print(kyo)
print(len(kyo))


Fixed submission:

from operator import itemgetter
 
n,m=map(int, input().split())
A=[]
B=[]
a=0
b=0
for i in range(m):
  a,b=map(int, input().split())
  A.append([a,b])

A.sort(key=itemgetter(1))
bri=0 #取った橋のうち番号最大の島のもの。bri=5なら4,5番目の島の橋

count=0

for i in range(m):
  a=A[i][0]
  b=A[i][1]
  
  if a>=bri:
    bri=b
    count+=1

print(count)