Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N,M = [int(x) for x in input().split()]

l = [[int(x) for x in input().split()] for _ in range(M)]



def do(l):
    

    count = 1

    l.sort()

    while True:

        # l2 = [v2 for (_,v2) in l]
        # l2.sort()
        

        nx = min(l,key=lambda x:x[1])[1]

        for i in range(len(l)):
            #print(l)
            
            if l[i][0] >= nx:
                #print("i")
                #print(i)
                #print(count)
                # h+=1
                # if i > 0:
                l = l[i:]
                count+=1
                break
            if i >= len(l)-1:
                return count
        if l == []:
            return count



result = do(l)
print(result)

Fixed submission:
import bisect

N,M = [int(x) for x in input().split()]

l = [[int(x) for x in input().split()] for _ in range(M)]



def do(l):

    count = 1

    l.sort()
    right = l[0][1]


    for i in range(len(l)):
        if l[i][0] >= right:
            right = l[i][1]
            count+=1
            continue
        if l[i][1] < right:
            right = l[i][1]
    return count

testl = [[x,x+1] for x in range(1)]

result = do(l)
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N,M = [int(x) for x in input().split()]

l = [[int(x) for x in input().split()] for _ in range(M)]



def do(l):
    

    count = 1

    l.sort()
    while True:
        l1 = [v1 for (v1,_) in l]
        l2 = [v2 for (_,v2) in l]
        l1.sort()
        l2.sort()

        nx = l2[0]

        for i in range(len(l)):
            #print(l)
            
            if l[i][0] >= nx:
                #print("i")
                #print(i)
                l = l[i:]
                #print(count)

                count+=1
                break
            if i >= len(l)-1:
                return count
        if l == []:
            return count



result = do(l)
print(result)

Fixed submission:
import bisect

N,M = [int(x) for x in input().split()]

l = [[int(x) for x in input().split()] for _ in range(M)]



def do(l):

    count = 1

    l.sort()
    right = l[0][1]


    for i in range(len(l)):
        if l[i][0] >= right:
            right = l[i][1]
            count+=1
            continue
        if l[i][1] < right:
            right = l[i][1]
    return count

testl = [[x,x+1] for x in range(1)]

result = do(l)
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N,M = [int(x) for x in input().split()]

l = [[int(x) for x in input().split()] for _ in range(M)]



def do(l):
    

    count = 1

    l.sort()
    while True:
        for i in range(len(l)):
            #print(l)
            l1 = [v1 for (v1,_) in l]
            l2 = [v2 for (_,v2) in l]
            l1.sort()
            l2.sort()

            nx = l2[0]
            if l[i][0] >= nx:
                #print("i")
                #print(i)
                l = l[i:]
                #print(count)

                count+=1
                break
            if i >= len(l)-1:
                return count




result = do(l)
print(result)

Fixed submission:
import bisect

N,M = [int(x) for x in input().split()]

l = [[int(x) for x in input().split()] for _ in range(M)]



def do(l):

    count = 1

    l.sort()
    right = l[0][1]


    for i in range(len(l)):
        if l[i][0] >= right:
            right = l[i][1]
            count+=1
            continue
        if l[i][1] < right:
            right = l[i][1]
    return count

testl = [[x,x+1] for x in range(1)]

result = do(l)
print(result)

Buggy python submission (verdict: Runtime Error):
import bisect

N,M = [int(x) for x in input().split()]

l = [[int(x) for x in input().split()] for _ in range(M)]



def do(l):
    l1 = [v1 for (v1,_) in l]
    l2 = [v2 for (_,v2) in l]
    l1.sort()
    l2.sort()

    count = 1

    l.sort()

    h = 0
    
    for i in range(len(l)):
        nx = l2[h]
        if l[i][0] >= nx:
            count+=1
            h+=1
            while l2[h] != l2[h+1]:
                if h+1 >= len(l2):
                    break
                h+=1
    return count




result = do(l)
print(result)

Fixed submission:
import bisect

N,M = [int(x) for x in input().split()]

l = [[int(x) for x in input().split()] for _ in range(M)]



def do(l):

    count = 1

    l.sort()
    right = l[0][1]


    for i in range(len(l)):
        if l[i][0] >= right:
            right = l[i][1]
            count+=1
            continue
        if l[i][1] < right:
            right = l[i][1]
    return count

testl = [[x,x+1] for x in range(1)]

result = do(l)
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N,M = [int(x) for x in input().split()]

l = [[int(x) for x in input().split()] for _ in range(M)]



def do(l):
    
    count = 0
    while True:
        l.sort()
        value = l[-1][0]+1
        l.sort(key=lambda v:v[1])
        l2 = [v2 for (_,v2) in l]
        index = bisect.bisect_left(l2,value)
        l = l[:index]

        count += 1
        if len(l)<1:
            break
    return count



result = do(l)
print(result)

Fixed submission:
import bisect

N,M = [int(x) for x in input().split()]

l = [[int(x) for x in input().split()] for _ in range(M)]



def do(l):

    count = 1

    l.sort()
    right = l[0][1]


    for i in range(len(l)):
        if l[i][0] >= right:
            right = l[i][1]
            count+=1
            continue
        if l[i][1] < right:
            right = l[i][1]
    return count

testl = [[x,x+1] for x in range(1)]

result = do(l)
print(result)