Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

ship_list1 = []
ship_list2 = []
count = 0
loop = False

for i in range(m):
    if ab[i][0] == 1:
        ship_list1.append(ab[i])
    if ab[i][1] == n:
        ship_list2.append(ab[i])

for ship1 in ship_list1:
    for ship2 in ship_list2:
        if ship1[1] == ship2[0]:
            print('POSSIBLE')
            count += 1
            loop = True
            break
    if loop:
        break

if count == 0:
    print('IMPOSSIBLE')

Fixed submission:
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

ship_list1 = []
ship_list2 = []
count = 0
loop = False

for i in range(m):
    if ab[i][0] == 1:
        ship_list1.append(ab[i][1])
    if ab[i][1] == n:
        ship_list2.append(ab[i][0])

if len(set(ship_list1) & set(ship_list2)) >= 1:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

ship_list1 = []
ship_list2 = []
count = 0

for i in range(m):
    if ab[i][0] == 1:
        ship_list1.append(ab[i])
    if ab[i][1] == n:
        ship_list2.append(ab[i])

for ship1 in ship_list1:
    for ship2 in ship_list2:
        if ship1[1] == ship2[0]:
            print('POSSIBLE')
            count += 1
            break
        else:
            continue

if count == 0:
    print('IMPOSSIBLE')

Fixed submission:
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

ship_list1 = []
ship_list2 = []
count = 0
loop = False

for i in range(m):
    if ab[i][0] == 1:
        ship_list1.append(ab[i][1])
    if ab[i][1] == n:
        ship_list2.append(ab[i][0])

if len(set(ship_list1) & set(ship_list2)) >= 1:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

ship = []
count = 0

for i in range(m):
    if count != 0:
        break
    if ab[i][1] == n:
        for j in range(m):
            if i == j:
                continue
            elif ab[i][0] == ab[j][1] and ab[j][0] == 1:
                print('POSSIBLE')
                count += 1
                break
            else:
                continue

if count == 0:
    print('IMPOSSIBLE')


Fixed submission:
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

ship_list1 = []
ship_list2 = []
count = 0
loop = False

for i in range(m):
    if ab[i][0] == 1:
        ship_list1.append(ab[i][1])
    if ab[i][1] == n:
        ship_list2.append(ab[i][0])

if len(set(ship_list1) & set(ship_list2)) >= 1:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

ship = []
count = 0

for i in range(m):
    if ab[i][1] == n:
        ship.append(ab[i])

for j in range(len(ship)):
    for i in range(m):
        if ab[i][1] == ship[j][0] and ab[i][0] == 1:
            print('POSSIBLE')
            count += 1
            break

if count == 0:
    print('IMPOSSIBLE')


Fixed submission:
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

ship_list1 = []
ship_list2 = []
count = 0
loop = False

for i in range(m):
    if ab[i][0] == 1:
        ship_list1.append(ab[i][1])
    if ab[i][1] == n:
        ship_list2.append(ab[i][0])

if len(set(ship_list1) & set(ship_list2)) >= 1:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')