Buggy python submission (verdict: Time Limit Exceeded):
import fractions
import sys
from functools import reduce
import math

input = sys.stdin.readline


def main():
    n, m = input_list()
    starts = []
    ends = []
    for _ in range(m):
        a, b = input_list()
        if a == 1:
            starts.append(b)
        elif b == n:
            ends.append(a)
    s = list(sorted(starts))
    e = list(sorted(ends))
    for a in s:
        if a in e:
            print('POSSIBLE')
            exit()
    print('IMPOSSIBLE')

def get_camulative(l):
    import itertools
    # 累積和
    return [0] + list(itertools.accumulate(l))

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def gcd(*numbers):
    return reduce(fractions.gcd, numbers)


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


if __name__ == "__main__":
    main()


Fixed submission:
n, m = map(int, input().split())

s = []
e = []
for _ in range(m):
  a, b = map(int, input().split())
  if a == 1:
    s.append(b)
  if b == n:
    e.append(a)

if set(s) & set(e):
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
import sys
from functools import reduce
import math

input = sys.stdin.readline


def main():
    n, m = input_list()
    starts = []
    ends = []
    for _ in range(m):
        a, b = input_list()
        if a == 1:
            starts.append((a, b))
        elif b == n:
            ends.append(a)
    for a, b in starts:
        if b in ends:
            print('POSSIBLE')
            exit()
    print('IMPOSSIBLE')

def get_camulative(l):
    import itertools
    # 累積和
    return [0] + list(itertools.accumulate(l))

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def gcd(*numbers):
    return reduce(fractions.gcd, numbers)


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


if __name__ == "__main__":
    main()


Fixed submission:
n, m = map(int, input().split())

s = []
e = []
for _ in range(m):
  a, b = map(int, input().split())
  if a == 1:
    s.append(b)
  if b == n:
    e.append(a)

if set(s) & set(e):
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

s = []
e = []
for _ in range(m):
  a, b = map(int, input().split())
  if a == 1:
    s.append((a, b))
  if b == n:
    e.append((a, b))
    
for a, b in s:
  for a2, b2 in e:
    if b == a2:
      print('POSSIBLE')
      exit()
print('IMPOSSIBLE')

Fixed submission:
n, m = map(int, input().split())

s = []
e = []
for _ in range(m):
  a, b = map(int, input().split())
  if a == 1:
    s.append(b)
  if b == n:
    e.append(a)

if set(s) & set(e):
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
target, m = map(int, input().split())

ship_count = 1
next_ships = []
next_start = []
for i in range(m):
  a, b = map(int, input().split())
  if a == 1:
    next_start.append(b)
  else:
    if b == target:
      next_ships.append([a, b])

if len(next_start) == 0:
  print('IMPOSSIBLE')
  exit(0)

for i in next_ships:
  a, b = i[0], i[1]
  if a in next_start:
    print('POSSIBLE')
    exit(0)

print('IMPOSSIBLE')


Fixed submission:
n, m = map(int, input().split())

s = []
e = []
for _ in range(m):
  a, b = map(int, input().split())
  if a == 1:
    s.append(b)
  if b == n:
    e.append(a)

if set(s) & set(e):
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
target, m = map(int, input().split())

ship_count = 1
next_ships = []
next_start = []
for i in range(m):
  a, b = map(int, input().split())
  if a == 1:
    next_start.append(b)
  else:
    next_ships.append([a, b])

if len(next_start) == 0:
  print('IMPOSSIBLE')
  exit(0)

for i in next_ships:
  a, b = i[0], i[1]
  if a in next_start and b == target:
    print('POSSIBLE')
    exit(0)

print('IMPOSSIBLE')


Fixed submission:
n, m = map(int, input().split())

s = []
e = []
for _ in range(m):
  a, b = map(int, input().split())
  if a == 1:
    s.append(b)
  if b == n:
    e.append(a)

if set(s) & set(e):
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')