Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
ab = sorted([list(map(int,input().split())) for _ in range(m)])
relaypoint = []
i = 0
while(ab[i][0] == 1):
  relaypoint.append(ab[i][1])
  i += 1
ab.sort(key = lambda ab:ab[1],reverse = True)
relaypoint = set(relaypoint)
x = len(relaypoint)
j = 0
flag = 0
while(ab[j][1] == n):
  if ab[j][0] in relaypoint:
    flag = 1
  j += 1
if flag == 1:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")


Fixed submission:
n,m = map(int,input().split())
ab = sorted([list(map(int,input().split())) for _ in range(m)])
relaypoint = []
for i in range(m):
  if ab[i][0] == 1:
    relaypoint.append(ab[i][1])
  else:
    break
ab.sort(key = lambda ab:ab[1],reverse = True)
relaypoint = set(relaypoint)
x = len(relaypoint)
j = 0
flag = 0
while(ab[j][1] == n):
  if ab[j][0] in relaypoint:
    flag = 1
  j += 1
if flag == 1:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
ab = sorted([list(map(int,input().split())) for _ in range(m)])
relaypoint = []
i = 0
while(ab[i][0] == 1):
  relaypoint.append(ab[i][1])
  i += 1
ab.sort(key = lambda ab:ab[1],reverse = True)
relaypoint = list(set(relaypoint))
x = len(relaypoint)
j = 0
flag = 0
while(ab[j][1] == n):
  if ab[j][0] in relaypoint:
    flag = 1
  j += 1
if flag == 1:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Fixed submission:
n,m = map(int,input().split())
ab = sorted([list(map(int,input().split())) for _ in range(m)])
relaypoint = []
for i in range(m):
  if ab[i][0] == 1:
    relaypoint.append(ab[i][1])
  else:
    break
ab.sort(key = lambda ab:ab[1],reverse = True)
relaypoint = set(relaypoint)
x = len(relaypoint)
j = 0
flag = 0
while(ab[j][1] == n):
  if ab[j][0] in relaypoint:
    flag = 1
  j += 1
if flag == 1:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
ab = sorted([list(map(int,input().split())) for _ in range(m)])
relaypoint = []
i = 0
while(ab[i][0] == 1):
  relaypoint.append(ab[i][1])
  i += 1
ab.sort(key = lambda ab:ab[1] reverse = True)
relaypoint = list(set(relaypoint))
x = len(relaypoint)
j = 0
flag = 0
while(ab[j][1] == 5):
  if ab[j][0] in relaypoint:
    flag = 1
if flag == 1:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Fixed submission:
n,m = map(int,input().split())
ab = sorted([list(map(int,input().split())) for _ in range(m)])
relaypoint = []
for i in range(m):
  if ab[i][0] == 1:
    relaypoint.append(ab[i][1])
  else:
    break
ab.sort(key = lambda ab:ab[1],reverse = True)
relaypoint = set(relaypoint)
x = len(relaypoint)
j = 0
flag = 0
while(ab[j][1] == n):
  if ab[j][0] in relaypoint:
    flag = 1
  j += 1
if flag == 1:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
ab=[list(map(int,input().split()))]
ab.sort()
medium = []
flag = 0
for i in range(m):
  if ab[i][0] == 1:
    medium.append(ab[i][1])
for j in range(m):
  if ab[j][0] in medium and ab[j][1] == n:
    flag = 1
if flag == 1:
  print("POSSIBLE")
else：
  print("IMPOSSIBLE")


Fixed submission:
n,m = map(int,input().split())
ab = sorted([list(map(int,input().split())) for _ in range(m)])
relaypoint = []
for i in range(m):
  if ab[i][0] == 1:
    relaypoint.append(ab[i][1])
  else:
    break
ab.sort(key = lambda ab:ab[1],reverse = True)
relaypoint = set(relaypoint)
x = len(relaypoint)
j = 0
flag = 0
while(ab[j][1] == n):
  if ab[j][0] in relaypoint:
    flag = 1
  j += 1
if flag == 1:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")