qyliang/CodeNanoFix huggingface dataset:
Buggy code:
def main():
    input = sys.stdin.readline
    n, m = map(int, input().split())
    a_b = [list(map(int, input().split())) for i in range(m)]
    a_b.sort(key=itemgetter(1))
    end = a_b[0][1]-2
    ans = 1 
    for i in range(m):
        if a_b[i][0]-1 > end:
            end = a_b[i][1]-2
            ans += 1
    print(ans)
if __name__ == "__main__":
    main()

Fixed code:
from operator import itemgetter
import sys
def main():
    input = sys.stdin.readline
    n, m = map(int, input().split())
    a_b = [list(map(int, input().split())) for i in range(m)]
    a_b.sort(key=itemgetter(1))
    end = a_b[0][1]-2
    ans = 1 
    for i in range(m):
        if a_b[i][0]-1 > end:
            end = a_b[i][1]-2
            ans += 1
    print(ans)
if __name__ == "__main__":
    main()
Buggy code:
n,m=map(int,input().split())
l=[]
for i in range(m):
    l.append(list(map(int,input().split())))
l.sort()
s=l[0][1]
ans=0
for i in range(1,m):
    if l[i][0]>=s:
        ans+=1
        s=l[i][1]
print(ans)

Fixed code:
n,m=map(int,input().split())
l=[]
for i in range(m):
    l.append(list(map(int,input().split())))
l.sort()
s=l[0][1]
ans=1
for i in range(1,m):
    if l[i][0]>=s:
        ans+=1
        s=l[i][1]
    if l[i][1]<=s:
        s=l[i][1]
print(ans)
Buggy code:
n,m=map(int,input().split())
points=[]
for i in range(m):
    a,b=map(int,input().split())
    points.append([a,b])
points = sorted(points)
arrow = float('-inf')
res = 0
for l,r in points:
    if l > arrow:
        res += 1
        arrow = r
    elif r < arrow:
        arrow = r
print(res)

Fixed code:
n,m=map(int,input().split())
points=[]
for i in range(m):
    a,b=map(int,input().split())
    points.append([a,b-1])
points = sorted(points)
arrow = float('-inf')
res = 0
#print(points)
for l,r in points:
    if l > arrow:
        res += 1
        arrow = r
    elif r < arrow:
        arrow = r
print(res)
Buggy code:
N,M = map(int,input().split())
l = [[0]*2 for i in range(M)]
sum = 0
for i in range(M):
    l[i][0],l[i][1] = map(int,input().split())
l.sort(key=lambda l:l[1])
x = 0
for i in range(M):
    if x<l[i][0]:
        x=l[i][1]
        sum+=1
print(sum)

Fixed code:
N,M = map(int,input().split())
l = [[0]*2 for i in range(M)]
sum = 0
for i in range(M):
    l[i][0],l[i][1] = map(int,input().split())
l.sort(key=lambda l:l[1])
x = 0
for i in range(M):
    if x<=l[i][0]:
        x=l[i][1]
        sum+=1
print(sum)
Buggy code:
n, m = map(int, input().split())
count = 0
s = [[]*2]*m
for i in range(0, m):
  s[i] = list(map(int, input().split()))

r = s[0][1]
count += 1
for i in range(1, m):
  if r > s[i][0] & r > s[i][1]:
    r = s[i][1]
  if r <= s[i][0]:
    r = s[i][1]
    count += 1
print(count)

Fixed code:
n, m = map(int, input().split())
count = 0
s = [[]*2]*m
for i in range(0, m):
  s[i] = list(map(int, input().split()))
s.sort()
r = s[0][1] - 1
count += 1
for i in range(1, m):
  if s[i][1] < r + 1:
    r = s[i][1] - 1
  if s[i][0] > r:
    r = s[i][1] - 1
    count += 1
print(count)
Buggy code:
N, M = (int(x) for x in input().split())
task_list = [
    {
        "index": i,
        "a": 0,
        "b": 0,
    } for i in range(M)
]
for i in range(M):
    task_list[i]["a"], task_list[i]["b"] = (int(x) for x in input().split())

task_list.sort(key=lambda x:x["b"])
ans, pointer = 0, 0
while pointer < M-1:
    task = task_list[pointer]
    j = 1
    while pointer+j < M and task_list[pointer+j]["a"] <= task["b"]\
    and task["b"] <= task_list[pointer+j]["b"]:
        j += 1
    else:
        ans += 1
        if pointer+j == M:
            print(ans)
            exit()
        else:
            pointer += 1
else:
    print(ans+1)
    exit()


Fixed code:
N, M = (int(x) for x in input().split())
task_list = [
    {
        "index": i,
        "a": 0,
        "b": 0,
    } for i in range(M)
]
for i in range(M):
    task_list[i]["a"], task_list[i]["b"] = (int(x) for x in input().split())

task_list.sort(key=lambda x:x["b"])
ans, pointer = 0, 0
while pointer < M-1:
    task = task_list[pointer]
    j = 1
    while pointer+j < M and task_list[pointer+j]["a"] <= task["b"]-1/2\
    and task["b"]-1/2 <= task_list[pointer+j]["b"]:
        j += 1
    else:
        ans += 1
        if pointer+j == M:
            print(ans)
            exit()
        else:
            pointer += j
else:
    print(ans+(M-pointer))
Buggy code:
from operator import itemgetter
n, m = map(int, input().split())

ab = [tuple(map(int, input().split())) for i in range(m)]

ab = sorted(ab, key=itemgetter(1))

count = 0
cut = 0
for i in range(m):
    if cut < ab[i][0]:
        count += 1
        cut = ab[i][1]

print(count)

Fixed code:
from operator import itemgetter
n, m = map(int, input().split())

ab = [tuple(map(int, input().split())) for i in range(m)]

ab = sorted(ab, key=itemgetter(1))

count = 0
cut = 0
for i in range(m):
    if cut <= ab[i][0]:
        count += 1
        cut = ab[i][1]

print(count)
Buggy code:
N, M = map(int, input().split())
x = []
for _ in range(M):
    a, b = map(int, input().split())
    x.append([a, b])

x.sort()
res = 0
right = 0
for i in range(M):
    if x[i][0] >= right:
        right = x[i][1]
        res += 1

print(res)

Fixed code:
N, M = map(int, input().split())
x = []
for _ in range(M):
    a, b = map(int, input().split())
    x.append([a, b])

x.sort(key=lambda x: x[1])
res = 0
right = 0
for i in range(M):
    if x[i][0] >= right:
        right = x[i][1]
        res += 1

print(res)
Buggy code:
N,M = map(int, input().split())
Bridge = []
for i in range(M):
    Bridge.append([int(x) for x in input().split()])

def minpair(A,B):
    C = []
    if A[1] > B[0]:
        C = [B[0],A[1]]
    elif B[1] > A[0]:
        C = [A[0],B[1]]
    return C

Bridge.sort(key=lambda x: x[0])
c = 0
ans = 0
while c <= M-2:
    Temp = minpair(Bridge[c],Bridge[c+1])
    if Temp == []:
        ans += 1
    else:
        Bridge[c+1] = Temp
    c += 1
print(ans+1)

Fixed code:
N,M = map(int, input().split())
Bridge = []
for i in range(M):
    Bridge.append([int(x) for x in input().split()])

def minpair(A,B):
    if A[1] <= B[0]:
        C = []
    elif B[0] < A[1] <= B[1]:
        C = [B[0],A[1]]
    else:
        C = B
    return C

Bridge.sort(key=lambda x: x[0])
c = 0
ans = 0
while c <= M-2:
    Temp = minpair(Bridge[c],Bridge[c+1])
    if Temp == []:
        ans += 1
    else:
        Bridge[c+1] = Temp
    c += 1
print(ans+1)
Buggy code:
_, M = map(int, input().split())
Schedule = [list(map(int, input().split())) for _ in range(M)]

Schedule = sorted(Schedule, key=lambda x: x[1])
cnt = 0
before_end = 0
for task in Schedule:
    start = task[0]
    end = task[1]
    if start < before_end:
        continue
    cnt += 1
    before_end = end

Fixed code:
_, M = map(int, input().split())
Schedule = [list(map(int, input().split())) for _ in range(M)]

Schedule = sorted(Schedule, key=lambda x: x[1])
cnt = 0
before_end = 0
for task in Schedule:
    start = task[0]
    end = task[1]
    if start < before_end:
        continue
    cnt += 1
    before_end = end
print(cnt)
Buggy code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 19 20:12:17 2019

@author: Owner
"""

from operator import itemgetter
import bisect

N, M = map(int, input().split())


ab = [(0, 0)]*M
for m in range(M):
    ab[m] = tuple(map(int, input().split()))

ab = tuple(sorted(ab, key = itemgetter(1)))

#print(ab)
x_rm = -1
res = 0
for m in range(M):
    if ab[m][0] <= x_rm:
        continue
    else:
        x_rm = ab[m][1]
        res += 1
    
    
        

print(res)



Fixed code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 19 20:12:17 2019

@author: Owner
"""

from operator import itemgetter
import bisect

N, M = map(int, input().split())


ab = [(0, 0)]*M
for m in range(M):
    ab[m] = tuple(map(int, input().split()))

ab = tuple(sorted(ab, key = itemgetter(1)))

#print(ab)
x_rm = -1
res = 0
for m in range(M):
    if ab[m][0] < x_rm:
        continue
    else:
        x_rm = ab[m][1]
        res += 1
    
    
        

print(res)
Buggy code:
N,M = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(M)]

ab.sort(key = lambda x:x[1])
ans = 0
last = -1
for a,b in ab:
    print(a,b)
    if last <= a:
        ans += 1
        last = b
        print('hogehogehoge',last,ans)
print(ans)


Fixed code:
N,M = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(M)]

ab.sort(key = lambda x:x[1])
ans = 0
last = -1
for a,b in ab:
    if last <= a:
        ans += 1
        last = b
print(ans)
Buggy code:
n,m=map(int,input().split())
AB=[]
append=AB.append
for i in range(m):
  a,b=map(int,input().split())
  append([ra,b])
AB.sort(key=lambda x:x[1])
c,ans=0,0
for a,b in AB:
  if a>=c:
    ans+=1
    c=b
print(ans)

Fixed code:
n,m=map(int,input().split())
AB=[]
append=AB.append
for i in range(m):
  a,b=map(int,input().split())
  append([a,b])
AB.sort(key=lambda x:x[1])
c,ans=0,0
for a,b in AB:
  if a>=c:
    ans+=1
    c=b
print(ans)
Buggy code:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
ab.sort(reverse=True)
L=10**6
ans=0
for a,b in ab[::-1]:
    if not a<=L<b:
        ans+=1
        L=a
print(ans)

Fixed code:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
ab.sort()
L=10**6
ans=0
for a,b in ab[::-1]:
    if not a<=L<b:
        ans+=1
        L=a
print(ans)
Buggy code:
N, M = map(int, input().split())

AB = []
for _ in range(M):
    a, b = map(int, input().split())
    AB.append((a, b))
    
fights = AB[:]

fights = sorted(fights, reverse=True)

import bisect


bridges = []
for a,b in fights:
    a_position = bisect.bisect(bridges, a)
    b_position = bisect.bisect(bridges, b)
    
    if a_position == b_position:
        bisect.insort(bridges, a)
        #print(bridges)

print(len(bridges))


        
        

Fixed code:
N, M = map(int, input().split())

AB = []
for _ in range(M):
    a, b = map(int, input().split())
    AB.append((a, b))

fights = AB[:]

fights = sorted(fights, reverse=True)

import bisect


bridges = []
for a,b in fights:
    a_position = bisect.bisect(bridges, a)
    b_position = bisect.bisect(bridges, b)
    
    if a_position == b_position:
        bisect.insort(bridges, a+1)
        #print(bridges)

print(len(bridges))
Buggy code:
N,M = map(int,input().split())
L = []
for _ in range(M):
    L.append(list(map(int,input().split())))
L = sorted(L,key=lambda x:x[1])
now = -10
cnt = 0
for x in L:
    if now < x[0]:
        now = x[1]
        cnt += 1
print(cnt)


Fixed code:
N,M = map(int,input().split())
L = []
for _ in range(M):
    L.append(list(map(int,input().split())))
L = sorted(L,key=lambda x:x[1])
now = -10
cnt = 0
for x in L:
    if now <= x[0]:
        now = x[1]
        cnt += 1
print(cnt)
Buggy code:
# Input
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()
ab = [(-1, -1)]
for _ in range(m):
    ai, bi = li_()
    ab.append((ai, bi))

ab.sort(key=lambda x: x[1])

ans = 0
cur = -1
for ai, bi in ab:
    if ai >= cur:
        ans += 1
        cur = bi

print(ans)




Fixed code:
# Input
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()
ab = []
for _ in range(m):
    ai, bi = li_()
    ab.append((ai, bi))

ab.sort(key=lambda x: x[1])

ans = 0
cur = -1
for ai, bi in ab:
    if ai >= cur:
        ans += 1
        cur = bi

print(ans)
Buggy code:
N,M = map(int,input().split())
war_list = []
divide_list = []
for i in range(M):
    war_list.append(list(map(int,input().split())))
war_list.sort(key = lambda x : x[1])

divide_list = [war_list[0][1]]
for i in range(1,M):
    if  war_list[i][0] < divide_list[-1]:
        pass
    else:
        divide_list.append(divide_list[-1])
    
print(len(divide_list))


Fixed code:
N,M = map(int,input().split())
war_list = []
divide_list = []
for i in range(M):
    war_list.append(list(map(int,input().split())))
war_list.sort(key = lambda x : x[1])

divide_list = [war_list[0][1]]
for i in range(1,M):
    if  war_list[i][0] < divide_list[-1]:
        pass
    else:
        divide_list.append(war_list[i][1])
    
print(len(divide_list))
Buggy code:

n, m = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(m)]
print(ab)
ab.sort(key=lambda x:x[1])
print(ab)

ans = 0
endplace = 0
for ai, bi in ab:
    if endplace <= ai:
        endplace = bi
        ans += 1
print(ans)


Fixed code:

n, m = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(m)]
ab.sort(key=lambda x:x[1])
ans = 0
endplace = 0
for ai, bi in ab:
    if endplace <= ai:
        endplace = bi
        ans += 1
print(ans)
Buggy code:
n,m=map(int,input().split())
w=[]
if n<99:
    print(w[1])
for i in range(m):
    a,b=map(int,input().split())
    w.append((a,b))
w.sort(reverse=True)
d=[]
for i in range(m):
    a,b=w.pop()
    if i==0:
        d.append([a,b])
    else:
        if d[-1][1]<=a:
            d.append([a,b])
        elif d[-1][1]>b:
            d[-1][1]=b
print(len(d))


Fixed code:
n,m=map(int,input().split())
w=[]
for i in range(m):
    a,b=map(int,input().split())
    w.append((a,b))
w.sort(reverse=True)
d=[]
for i in range(m):
    a,b=w.pop()
    if i==0:
        d.append([a,b])
    else:
        if d[-1][1]<=a:
            d.append([a,b])
        elif d[-1][1]>b:
            d[-1][1]=b
print(len(d))
Buggy code:
N,M=map(int,input().split())
B=[]
for i in range(1,M):
  a,b=map(int,input().split())
  B.append([a,b])
B.sort(key=lambda x:x[1])
ans=0
c=-1
for item in B:
  if item[1]!=c:
    c=item[1]
    ans+=1
print(ans)

Fixed code:
N,M=map(int,input().split())
B=[]
for i in range(M):
  a,b=map(int,input().split())
  B.append([a,b])
B.sort(key=lambda x:x[1])
ans=1
c=[B[0][1]]
for item in B:
  if c[-1]<=item[0]:
    c.append(item[1])
    ans+=1
print(ans)
Buggy code:
N, M = map(int, input().split())
AB = sorted([[int(i) for i in input().split()] for i in range(M)], key = lambda x: x[1])

cnt = 1
posi = AB[0][1]
for i in range(1, M):
    if AB[i][0] > posi:
        cnt += 1
        posi = AB[i][1]

print(cnt)

Fixed code:
N, M = map(int, input().split())
AB = sorted([[int(i) for i in input().split()] for i in range(M)], key = lambda x: x[1])

cnt = 1
posi = AB[0][1]
for i in range(1, M):
    if AB[i][0] >= posi:
        cnt += 1
        posi = AB[i][1]

print(cnt)
Buggy code:
n,m = [int(i) for i in input().split()]
e = [[int(j) for j in input().split()] for i in range(m)]
sorted(e,key= lambda x : x[1])
s=[]
for i in e:
  if i[0]<=s[-1]:
    pass
  else:
    s.append(i[1]-1)
    
print(len(s))

Fixed code:
n,m = [int(i) for i in input().split()]
e = [[int(j) for j in input().split()] for i in range(m)]
new_e =sorted(e,key= lambda x : x[1])
s=[]
for i in new_e:
  if s!= [] and i[0]<=s[-1]:
    pass
  else:
    s.append(i[1]-1)

print(len(s))
Buggy code:
n, m = map(int, input().split())
SG = sorted([[int(i) for i in input().split()] for i in range(m)], key = lambda x: x[1])

cnt = 0
b = 0
for s, g in SG:
    if s >= b:
        b = s + 1
        cnt += 1
        
print(cnt)

Fixed code:
n, m = map(int, input().split())
SG = sorted([[int(i) for i in input().split()] for i in range(m)], key = lambda x: x[1])

cnt = 1
b = SG[0][1]
for s, g in SG:
    if s >= b:
        b = g
        cnt += 1
        
print(cnt)
Buggy code:
# coding: utf-8
# Your code here!
N,M =map(int,input().split(" "))

num =[]
for i in range(M):
    l,m =map(int,input().split(" "))
    x =[m,l]
    num.append(x)
num.sort()
#print(num)
t = num[0][0]
ans =1
for i in range(1,M):
    k =num[i][1]
    if t<k:
        t = k
        ans +=1
print(ans)
        

Fixed code:
# coding: utf-8
# Your code here!
N,M =map(int,input().split(" "))

num =[]
for i in range(M):
    l,m =map(int,input().split(" "))
    x =[m,l]
    num.append(x)
num.sort()
#print(num)
t = num[0][0]
ans =1
for i in range(1,M):
    k =num[i][1]
    if t<=k:
        t = num[i][0]
        ans +=1
        #print(k)
print(ans)
Buggy code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, M = map(int, input().split())
cut = []
for _ in range(M):
    a, b = map(int, input().split())
    cut.append([a, b])

cut = sorted(cut, key=lambda x: x[0])

ans = 1
ind = 0

print(cut)

s = cut[ind][0]
e = cut[ind][1]
while ind < M:
    n_s, n_e = cut[ind]
    if n_s < e:
        e = min(e, n_e)
    else:
        s = n_s
        e = n_e
        ans += 1
    ind += 1


print(ans)


Fixed code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, M = map(int, input().split())
cut = []
for _ in range(M):
    a, b = map(int, input().split())
    cut.append([a, b])

cut = sorted(cut, key=lambda x: x[0])

ans = 1
ind = 0


s = cut[ind][0]
e = cut[ind][1]
while ind < M:
    n_s, n_e = cut[ind]
    if n_s < e:
        e = min(e, n_e)
    else:
        s = n_s
        e = n_e
        ans += 1
    ind += 1


print(ans)
Buggy code:
a_b = []
for _ in range(M):
    a, b = map(int, input().split())
    a_b.append((a, b))
a_b.sort(key=lambda x: x[0])

r = a_b[0][1]
ans = 1
for a, b in a_b[1:]:
    if a >= r:
        r = b
        ans += 1
        continue
    if b < r:
        r = b
print(ans)

Fixed code:
N, M = map(int, input().split())
a_b = []
for _ in range(M):
    a, b = map(int, input().split())
    a_b.append((a, b))
a_b.sort(key=lambda x: x[0])

r = a_b[0][1]
ans = 1
for a, b in a_b[1:]:
    if a >= r:
        r = b
        ans += 1
        continue
    if b < r:
        r = b
print(ans)
Buggy code:
N,M = map(int,input().split())

claims = []
for i in range(M):
  claims.append(list(map(int,input().split())))
  
claims.sort()

killed = 0
last_killed = [-1,-1]
for claim in claims:
  if (last_killed[1] < claim[0] or last_killed[0] >= claim[1]):
    last_killed = [claim[0],claim[1] -1]
    killed += 1

print(killed)

Fixed code:
N,M = map(int,input().split())

claims = []
for i in range(M):
  claims.append(list(map(int,input().split())))
  
claims.sort()

killed = 0
last_killed = [-1,-1]
for claim in claims:
  if (last_killed[1] < claim[0] or last_killed[0] >= claim[1]):
    last_killed = [claim[0],claim[1] -1]
    killed += 1
  last_killed = [max(last_killed[0],claim[0]),min(last_killed[1],claim[1] -1)]
print(killed)
Buggy code:
N,M=map(int,input().split())
AB=[]
for _ in range(M):
    AB.append(tuple(map(int,input().split())))
    
request_max=0
request_num=0

AB.sort(key=lambda x:x[1])
for (a,b) in AB:
    if a>request_max:
        request_num +=1
        request_max = b
print(request_num)

Fixed code:
N,M=map(int,input().split())
AB=[]
for _ in range(M):
    AB.append(tuple(map(int,input().split())))
    
request_max=0
request_num=0

AB.sort(key=lambda x:x[1])
for (a,b) in AB:
    if a>=request_max:
        request_num +=1
        request_max = b
print(request_num)
Buggy code:
N,M = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(M)]

ab.sort(key = lambda x:x[1])
ans = 0
last = -1
for a,b in ab:
    print(a,b)
    if last <= a:
        ans += 1
        last = b
print(ans)


Fixed code:
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]
x = 0
ab.sort(key=lambda x: x[1])
ans = 0
for a, b in ab:
    if x <= a:
        ans += 1
        x = b
print(ans)
Buggy code:
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
l.sort(key=lambda x : x[1])
a=0
b=0
for x in l:
  if x[0]>b:
    b=x[0]
    a+=1


Fixed code:
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
l.sort(key=lambda x : x[1])
a=0
b=0
for x in l:
  if x[0]>=b:
    b=x[1]
    a+=1
print(a)
Buggy code:
# -*- coding:utf-8 -*-
n, m = map(int, input().split())
d = []
for i in range(m):
    a, b = map(int, input().split())
    d.append([a, b])

d.sort(key=lambda x: (x[1], x[0]))

mn = 100000000
ans = 0
for a, b in d:
    if a >= mn:
        ans += 1
        mn = b
    mn = min(mn, b)

if mn != 100000000:
    ans += 1
print(ans)

print(ans + 1)


Fixed code:
# -*- coding:utf-8 -*-
n, m = map(int, input().split())
d = []
for i in range(m):
    a, b = map(int, input().split())
    d.append([a, b])

d.sort(key=lambda x: (x[0], x[1]))

mn = 100000000
ans = 0
for a, b in d:
    if a >= mn:
        ans += 1
        mn = b
    mn = min(mn, b)

if mn != 100000000:
    ans += 1
print(ans)
Buggy code:
N, M = map(int, input().split())
l = [list(map(int, input().split())) for i in range(M)]
sorted(l, key = lambda l:l[1])

p_num = -1
ans = 0

for i in range(M):
	if l[i][0] > p_num:
		p_num = l[i][1] - 1
		ans += 1

print(ans)

Fixed code:
N, M = map(int, input().split())
l = [list(map(int, input().split())) for i in range(M)]
l = sorted(l, key = lambda l:(l[1]))

p_num = -1
ans = 0

for i in range(M):
	if not l[i][0] <= p_num:
		p_num = l[i][1] - 1
		ans += 1

print(ans)
Buggy code:
n, m = list(map(int, input().split()))
ab = list(list(map(int, input().split())) for i in range(m))
ab = sorted(ab, key=lambda x: x[1])
bridge = 0
count = 0
for i in range(m):
    if ab[i][0] <= bridge:
        continue
    else:
        bridge = ab[i][0]
        count = count + 1
    if count == n-1:
        break
    else:
        continue
print(count)

Fixed code:
n, m = list(map(int, input().split()))
ab = list(list(map(int, input().split())) for i in range(m))
ab = sorted(ab, key=lambda x: x[1])
bridge = 0
count = 0
for i in range(m):
    if ab[i][0] < bridge:
        continue
    else:
        bridge = ab[i][1]
        count = count + 1
    if count == n-1:
        break
    else:
        continue
print(count)
Buggy code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def solve(N, M, a, b):
    pass


def main():
    N, M = map(int, input().split())
    l = []
    for _ in range(M):
        a, b, = map(int, input().split())
        l.append((a, b))
    l.sort()

    ans = 0
    mini = INF
    for a, b in l:
        if mini <= a:
            ans += 1
        mini = min(mini, b)

    print(ans + 1)

if __name__ == '__main__':
    main()


Fixed code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def solve(N, M, a, b):
    pass


def main():
    N, M = map(int, input().split())
    l = []
    for _ in range(M):
        a, b, = map(int, input().split())
        l.append((a, b))
    l.sort()

    ans = 0
    mini = INF
    for a, b in l:
        if mini <= a:
            ans += 1
            mini = INF
        mini = min(mini, b)

    print(ans + 1)

if __name__ == '__main__':
    main()