Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ab_list = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]

lis = [[] for i in range(N)]

for i in range(M):
    lis[ab_list[i][0]].append(ab_list[i][1])

que = [[0, 0, lis[0], []]]
ends = []
res = False

while que:
    count, now, next_nodes, visited = que.pop()
    ends.append(visited)
    visited.append(now)
    for node in next_nodes:
        if node in visited or count == 2:
            continue
        que.append([count + 1, node, lis[node], visited[:]])

print()

if N - 1 in set(sum(ends, [])):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Fixed submission:
N, M = map(int, input().split())
ab_list = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]

lis = [[] for i in range(N)]

for i in range(M):
    lis[ab_list[i][0]].append(ab_list[i][1])

que = [[0, 0, lis[0], []]]
ends = []
res = False

while que:
    count, now, next_nodes, visited = que.pop()
    visited.append(now)
    if now == N - 1:
        ends = visited[:]
    for node in next_nodes:
        if node in visited or count == 2:
            continue
        que.append([count + 1, node, lis[node], visited[:]])

if N - 1 in ends:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ab_list = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]

lis = [[] for i in range(N)]

for i in range(M):
    lis[ab_list[i][0]].append(ab_list[i][1])

que = [[0, 0, lis[0], []]]
ends = []
res = False

while que:
    count, now, next_nodes, visited = que.pop()
    ends.append(visited)
    visited.append(now)
    for node in next_nodes:
        if node in visited or count == 2:
            continue
        que.append([count + 1, node, lis[node], visited[:]])

print()

if N - 1 in sum(ends, []):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Fixed submission:
N, M = map(int, input().split())
ab_list = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]

lis = [[] for i in range(N)]

for i in range(M):
    lis[ab_list[i][0]].append(ab_list[i][1])

que = [[0, 0, lis[0], []]]
ends = []
res = False

while que:
    count, now, next_nodes, visited = que.pop()
    visited.append(now)
    if now == N - 1:
        ends = visited[:]
    for node in next_nodes:
        if node in visited or count == 2:
            continue
        que.append([count + 1, node, lis[node], visited[:]])

if N - 1 in ends:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ab_list = [list(map(int, input().split())) for i in range(M)]

end_list = list(filter(lambda x: x[1] == N, ab_list))

res = False

for end in end_list:
    if res:
        break
    if len(list(filter(lambda x: (x[1] == end[0]) and (x[0] == 1) or end[0] == 1, ab_list))) > 0:
        res = True
        break


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


Fixed submission:
N, M = map(int, input().split())
ab_list = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]

lis = [[] for i in range(N)]

for i in range(M):
    lis[ab_list[i][0]].append(ab_list[i][1])

que = [[0, 0, lis[0], []]]
ends = []
res = False

while que:
    count, now, next_nodes, visited = que.pop()
    visited.append(now)
    if now == N - 1:
        ends = visited[:]
    for node in next_nodes:
        if node in visited or count == 2:
            continue
        que.append([count + 1, node, lis[node], visited[:]])

if N - 1 in ends:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ab_list = [list(map(int, input().split())) for i in range(M)]

end_list = list(filter(lambda x: x[1] == N, ab_list))

res = False

for end in end_list:
    if len(list(filter(lambda x: (x[1] == end[0]) and (x[0] == 1) or end[0] == 1, ab_list))) > 0:
        res = True
        break


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


Fixed submission:
N, M = map(int, input().split())
ab_list = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]

lis = [[] for i in range(N)]

for i in range(M):
    lis[ab_list[i][0]].append(ab_list[i][1])

que = [[0, 0, lis[0], []]]
ends = []
res = False

while que:
    count, now, next_nodes, visited = que.pop()
    visited.append(now)
    if now == N - 1:
        ends = visited[:]
    for node in next_nodes:
        if node in visited or count == 2:
            continue
        que.append([count + 1, node, lis[node], visited[:]])

if N - 1 in ends:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ab_list = [list(map(int, input().split())) for i in range(M)]

end_list = list(filter(lambda x: x[1] == N, ab_list))

res = False

for end in end_list:
    if end[0] == 1:
        res = True
        break

if not res:
    for end in end_list:
        if len(list(filter(lambda x: (x[1] == end[0]) and (x[0] == 1), ab_list))) > 0:
            res = True
            break


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



Fixed submission:
N, M = map(int, input().split())
ab_list = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]

lis = [[] for i in range(N)]

for i in range(M):
    lis[ab_list[i][0]].append(ab_list[i][1])

que = [[0, 0, lis[0], []]]
ends = []
res = False

while que:
    count, now, next_nodes, visited = que.pop()
    visited.append(now)
    if now == N - 1:
        ends = visited[:]
    for node in next_nodes:
        if node in visited or count == 2:
            continue
        que.append([count + 1, node, lis[node], visited[:]])

if N - 1 in ends:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ab_list = [list(map(int, input().split())) for i in range(M)]

ab_list.sort()

end_list = list(filter(lambda x: x[1] == N, ab_list))

res = False

for end in end_list:
    if end[0] == 1:
        res = True
        break

if not res:
    for end in end_list:
        if len(list(filter(lambda x: (x[1] == end[0]) and (x[0] == 1), ab_list))) > 0:
            res = True
            break


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


Fixed submission:
N, M = map(int, input().split())
ab_list = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]

lis = [[] for i in range(N)]

for i in range(M):
    lis[ab_list[i][0]].append(ab_list[i][1])

que = [[0, 0, lis[0], []]]
ends = []
res = False

while que:
    count, now, next_nodes, visited = que.pop()
    visited.append(now)
    if now == N - 1:
        ends = visited[:]
    for node in next_nodes:
        if node in visited or count == 2:
            continue
        que.append([count + 1, node, lis[node], visited[:]])

if N - 1 in ends:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ab_list = [list(map(int, input().split())) for i in range(M)]

ab_list.sort()

end_list = list(filter(lambda x: x[1] == N, ab_list))

res = False

for end in end_list:
    if end[0] == 1:
        res = True
        break

if not res:
    for end in end_list:
        if res:
            break
        for ab in list(filter(lambda x: x[1] == end[0], ab_list)):
            if ab[0] == 1:
                res = True
                break

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


Fixed submission:
N, M = map(int, input().split())
ab_list = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]

lis = [[] for i in range(N)]

for i in range(M):
    lis[ab_list[i][0]].append(ab_list[i][1])

que = [[0, 0, lis[0], []]]
ends = []
res = False

while que:
    count, now, next_nodes, visited = que.pop()
    visited.append(now)
    if now == N - 1:
        ends = visited[:]
    for node in next_nodes:
        if node in visited or count == 2:
            continue
        que.append([count + 1, node, lis[node], visited[:]])

if N - 1 in ends:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ab_list = [list(map(int, input().split())) for i in range(M)]

ab_list.sort()

start_list = list(filter(lambda x: x[0] == 1, ab_list))

res = False


for start in start_list:
    if start[1] == N:
        res = True
        break
        
if not res:
    for start in start_list:
        if res:
            break
        for ab in list(filter(lambda x: x[0] == start[1], ab_list)):
            if ab[1] == N:
                res = True
                break

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


Fixed submission:
N, M = map(int, input().split())
ab_list = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]

lis = [[] for i in range(N)]

for i in range(M):
    lis[ab_list[i][0]].append(ab_list[i][1])

que = [[0, 0, lis[0], []]]
ends = []
res = False

while que:
    count, now, next_nodes, visited = que.pop()
    visited.append(now)
    if now == N - 1:
        ends = visited[:]
    for node in next_nodes:
        if node in visited or count == 2:
            continue
        que.append([count + 1, node, lis[node], visited[:]])

if N - 1 in ends:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ab_list = [list(map(int, input().split())) for i in range(M)]

ab_list.sort()

start_list = list(filter(lambda x: x[0] == 1, ab_list))

res = False

while not res:
    for start in start_list:
        if start[1] == N:
            res = True
    for start in start_list:
        for ab in list(filter(lambda x: x[0] == start[1], ab_list)):
            if ab[1] == N:
                res = True

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


Fixed submission:
N, M = map(int, input().split())
ab_list = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]

lis = [[] for i in range(N)]

for i in range(M):
    lis[ab_list[i][0]].append(ab_list[i][1])

que = [[0, 0, lis[0], []]]
ends = []
res = False

while que:
    count, now, next_nodes, visited = que.pop()
    visited.append(now)
    if now == N - 1:
        ends = visited[:]
    for node in next_nodes:
        if node in visited or count == 2:
            continue
        que.append([count + 1, node, lis[node], visited[:]])

if N - 1 in ends:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ab_list = [list(map(int, input().split())) for i in range(M)]

ab_list.sort()

start_list = list(filter(lambda x: x[0] == 1, ab_list))

res = False

if M > 1:
    for start in start_list:
        for ab in list(filter(lambda x: x[0] == start[1], ab_list)):
            if ab[1] == N:
                res = True
else:
    for start in start_list:
        if start[1] == N:
            res = True

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


Fixed submission:
N, M = map(int, input().split())
ab_list = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]

lis = [[] for i in range(N)]

for i in range(M):
    lis[ab_list[i][0]].append(ab_list[i][1])

que = [[0, 0, lis[0], []]]
ends = []
res = False

while que:
    count, now, next_nodes, visited = que.pop()
    visited.append(now)
    if now == N - 1:
        ends = visited[:]
    for node in next_nodes:
        if node in visited or count == 2:
            continue
        que.append([count + 1, node, lis[node], visited[:]])

if N - 1 in ends:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")