Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().strip().split(" "))

edge = []

for m in range(M):
    a, b = map(int, input().strip().split(" "))
    if (a == 1 or a == N) or (b == 1 or b == N):
        edge.append((a, b))

res = False
for n in range(N):
    if len([e for e in edge if e[0] == 1 and e[1] == n]) > 0 and len([e for e in edge if e[0] == n and e[1] == N]) > 0:
        print("POSSIBLE")
        res = True
        break


if not res:
    print("IMPOSSIBLE")


Fixed submission:
N, M = map(int, input().strip().split(" "))

to_one = [False] * N
to_N = [False] * N
for m in range(M):
    a, b = map(int, input().strip().split(" "))
    if a == 1:
        to_one[b] = True
    if b == N:
        to_N[a] = True

res = False
for n in range(2, N):
    if to_N[n] and to_one[n]:
        print("POSSIBLE")
        res = True
        break

if not res:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().strip().split(" "))

edge = []

for m in range(M):
    a, b = map(int, input().strip().split(" "))
    edge.append((a,b))

to_one = [False] * N
to_N = [False] * N

for n in range(N):
     to_one[n] = len([e for e in edge if e[0] == 1 and e[1] == n]) > 0
     to_N[n] = len([e for e in edge if e[0] == n and e[1] == N]) > 0

res = False
for n in range(N):
    if to_one[n] and to_N[n]:
        print("POSSIBLE")
        res = True
        break

if not res:
    print("IMPOSSIBLE")

Fixed submission:
N, M = map(int, input().strip().split(" "))

to_one = [False] * N
to_N = [False] * N
for m in range(M):
    a, b = map(int, input().strip().split(" "))
    if a == 1:
        to_one[b] = True
    if b == N:
        to_N[a] = True

res = False
for n in range(2, N):
    if to_N[n] and to_one[n]:
        print("POSSIBLE")
        res = True
        break

if not res:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().strip().split(" "))

edge = []

for m in range(M):
    a, b = map(int, input().strip().split(" "))
    edge.append((a,b))

one_step = [e[1] for e in edge if e[0] == 1]

pos = False
for i, o in enumerate(one_step):
    pos = len([x for x in edge if  x[0] == o and x[1] == N]) > 0
    if pos:
        break

if pos:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Fixed submission:
N, M = map(int, input().strip().split(" "))

to_one = [False] * N
to_N = [False] * N
for m in range(M):
    a, b = map(int, input().strip().split(" "))
    if a == 1:
        to_one[b] = True
    if b == N:
        to_N[a] = True

res = False
for n in range(2, N):
    if to_N[n] and to_one[n]:
        print("POSSIBLE")
        res = True
        break

if not res:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().strip().split(" "))

edge = []

for m in range(M):
    a, b = map(int, input().strip().split(" "))
    edge.append((a,b))

one_step = []
for i, e in enumerate(edge):
    if e[0] == 1:
        one_step.append(e[1])

pos = False
for i, o in enumerate(one_step):
    for e in filter(lambda x: x[0] == o, edge):
        if e[1] == N:
            print("POSSIBLE")
            pos = True

if not pos:
    print("IMPOSSIBLE")

Fixed submission:
N, M = map(int, input().strip().split(" "))

to_one = [False] * N
to_N = [False] * N
for m in range(M):
    a, b = map(int, input().strip().split(" "))
    if a == 1:
        to_one[b] = True
    if b == N:
        to_N[a] = True

res = False
for n in range(2, N):
    if to_N[n] and to_one[n]:
        print("POSSIBLE")
        res = True
        break

if not res:
    print("IMPOSSIBLE")