Buggy python submission (verdict: Time Limit Exceeded):
import sys
from operator import itemgetter
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    ab_list = [tuple(map(int, input().split())) for _ in range(m)]
    deleted = [False for _ in range(n-1)]
    for ab in sorted(ab_list, key = itemgetter(1)):
        if True in set(deleted[ab[0]-1:ab[1]-1]):
            continue
        else:
            deleted[ab[1]-2] = True
    print(len([b for b in deleted if b is True]))

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from operator import itemgetter
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    ab_list = [tuple(map(int, input().split())) for _ in range(m)]
    ab_list.sort(key = itemgetter(1))
    del_max = -10
    ans = 0
    for ab in ab_list:
        if ab[0] - 1 > del_max:
            ans += 1
            del_max = ab[1] - 2
    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from operator import itemgetter
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    ab_list = [tuple(map(int, input().split())) for _ in range(m)]
    deleted = [False for _ in range(n-1)]
    for ab in sorted(ab_list, key = itemgetter(1)):
        if True in set(deleted[ab[0]-1:ab[1]-1]):
            continue
        else:
            deleted[ab[1]-2] = True
    print(len([b for b in deleted if b is True]))

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from operator import itemgetter
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    ab_list = [tuple(map(int, input().split())) for _ in range(m)]
    ab_list.sort(key = itemgetter(1))
    del_max = -10
    ans = 0
    for ab in ab_list:
        if ab[0] - 1 > del_max:
            ans += 1
            del_max = ab[1] - 2
    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from operator import itemgetter
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    ab_list = [tuple(map(int, input().split())) for _ in range(m)]
    deleted = [False for _ in range(n-1)]
    for ab in sorted(ab_list, key = itemgetter(1)):
        if True in set(deleted[ab[0]-1:ab[1]-1]):
            continue
        else:
            deleted[ab[1]-2] = True
    print(len([b for b in deleted if b is True]))

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from operator import itemgetter
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    ab_list = [tuple(map(int, input().split())) for _ in range(m)]
    ab_list.sort(key = itemgetter(1))
    del_max = -10
    ans = 0
    for ab in ab_list:
        if ab[0] - 1 > del_max:
            ans += 1
            del_max = ab[1] - 2
    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from operator import itemgetter
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    ab_list = [tuple(map(int, input().split())) for _ in range(m)]
    deleted = [False for _ in range(n-1)]
    for ab in sorted(ab_list, key = itemgetter(1)):
        if True in deleted[ab[0]-1:ab[1]-1]:
            continue
        else:
            deleted[ab[1]-2] = True
    print(len([b for b in deleted if b is True]))

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from operator import itemgetter
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    ab_list = [tuple(map(int, input().split())) for _ in range(m)]
    ab_list.sort(key = itemgetter(1))
    del_max = -10
    ans = 0
    for ab in ab_list:
        if ab[0] - 1 > del_max:
            ans += 1
            del_max = ab[1] - 2
    print(ans)

if __name__ == '__main__':
    main()