Buggy python submission (verdict: Time Limit Exceeded):
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,M = map(int, input().split())
    bridges = [False]*(N-1)
    closest_enemy = [-1]*N
    for _ in range(M):
        a,b = map(int, input().split())
        closest_enemy[b-1] = max(a-1,closest_enemy[b-1])
    for i in range(1,N):
        if closest_enemy[i] < 0: continue

        if True in bridges[closest_enemy[i]:i]:
            continue
        else:
            bridges[i-1] = True
    print(bridges.count(True))

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,M = map(int, input().split())
    battles = [[] for _ in range(N)]
    for _ in range(M):
        a,b = map(int, input().split())
        battles[b-1].append(a-1)

    x = -1
    ans = 0
    for i in range(1,N):
        battle = battles[i]
        if len(battle) == 0: continue

        closest_idx = max(battle)
        if x < closest_idx:
            ans += 1
            x = i-1
    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,M = map(int, input().split())
    bridges = [False]*(N-1)
    battles = [[] for _ in range(N)]
    for _ in range(M):
        a,b = map(int, input().split())
        battles[b-1].append(a-1)
    for i in range(1,N):
        battle = battles[i]
        if len(battle) == 0: continue

        closest_idx = max(battle)
        if True in bridges[closest_idx:i]:
            continue
        else:
            bridges[i-1] = True
    print(bridges.count(True))

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,M = map(int, input().split())
    battles = [[] for _ in range(N)]
    for _ in range(M):
        a,b = map(int, input().split())
        battles[b-1].append(a-1)

    x = -1
    ans = 0
    for i in range(1,N):
        battle = battles[i]
        if len(battle) == 0: continue

        closest_idx = max(battle)
        if x < closest_idx:
            ans += 1
            x = i-1
    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,M = map(int, input().split())
    bridges = [False]*(N-1)
    battles = [[] for _ in range(N)]
    for _ in range(M):
        a,b = map(int, input().split())
        battles[b-1].append(a-1)
    for i in range(1,N):
        battle = battles[i]
        if len(battle) == 0: continue

        closest_idx = max(battle)
        for bridge_idx in range(closest_idx, i):
            if bridges[bridge_idx]: break
        else:
            bridges[i-1] = True
    print(bridges.count(True))

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,M = map(int, input().split())
    battles = [[] for _ in range(N)]
    for _ in range(M):
        a,b = map(int, input().split())
        battles[b-1].append(a-1)

    x = -1
    ans = 0
    for i in range(1,N):
        battle = battles[i]
        if len(battle) == 0: continue

        closest_idx = max(battle)
        if x < closest_idx:
            ans += 1
            x = i-1
    print(ans)

if __name__ == '__main__':
    main()