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

a_list = []
tmp_start = []
tmp_goal = []
for i in range(m):
    a, b = map(int, input().split())
    
    # 島1から出ている船の行き先
    if a == 1:
        tmp_start.append(b)
    
    if b == n:
        tmp_goal.append(a)
    

    # 島1から意外の運航便のリスト
    #else:
    #    a_list.append([a, b])


for j in tmp_start:
    if j in tmp_goal:
        print('POSSIBLE')
        break

else:
    print('IMPOSSIBLE')

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

a_list = []
tmp_start = []
tmp_goal = []
for i in range(m):
    a, b = map(int, input().split())
    
    # 島1から出ている船の行き先
    if a == 1:
        tmp_start.append(b)
    
    if b == n:
        tmp_goal.append(a)
    

    # 島1から意外の運航便のリスト
    #else:
    #    a_list.append([a, b])

agree = set(tmp_start) & set(tmp_goal)

if len(agree) == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

#for j in tmp_start:
#    if j in tmp_goal:
#        print('POSSIBLE')
#        break

#else:
#    print('IMPOSSIBLE')

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

a_list = []
tmp = []
for i in range(m):
    a, b = map(int, input().split())
    
    # 島1から出ている船の行き先
    if a == 1:
        tmp.append(b)
    
    # 島1から意外の運航便のリスト
    else:
        a_list.append([a, b])

a_list.sort(key=lambda x: x[0])
tmp.sort()
#print(a_list)
#print(tmp)

possible = 0
for b in tmp:
    #print(a_list)

    for j in range(len(a_list)):
        if len(a_list) == 1:
            if a_list[0][1] == n:
                possible = 1

        elif a_list[j][0] < b:
            a_list.pop(j)

        elif a_list[j][0] == b:
            if a_list[j][1] == n:
                possible = 1
                break
        else:
            break

if possible == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

    


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

a_list = []
tmp_start = []
tmp_goal = []
for i in range(m):
    a, b = map(int, input().split())
    
    # 島1から出ている船の行き先
    if a == 1:
        tmp_start.append(b)
    
    if b == n:
        tmp_goal.append(a)
    

    # 島1から意外の運航便のリスト
    #else:
    #    a_list.append([a, b])

agree = set(tmp_start) & set(tmp_goal)

if len(agree) == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

#for j in tmp_start:
#    if j in tmp_goal:
#        print('POSSIBLE')
#        break

#else:
#    print('IMPOSSIBLE')

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

a_list = []
tmp = []
for i in range(m):
    a, b = map(int, input().split())
    
    # 島1から出ている船の行き先
    if a == 1:
        tmp.append(b)
    
    # 島1から意外の運航便のリスト
    else:
        a_list.append([a, b])

a_list.sort(key=lambda x: x[0])
tmp.sort()
#print(a_list)
#print(tmp)

possible = 0
for b in tmp:
    #print(a_list)

    for j in range(len(a_list)):
        if len(a_list) == 1:
            if a_list[0][1] == n:
                possible = 1

        elif a_list[j][0] < b:
            a_list.pop(j)

        elif a_list[j][0] == b:
            if a_list[j][1] == n:
                possible = 1
                break
        else:
            break

if possible == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

    


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

a_list = []
tmp_start = []
tmp_goal = []
for i in range(m):
    a, b = map(int, input().split())
    
    # 島1から出ている船の行き先
    if a == 1:
        tmp_start.append(b)
    
    if b == n:
        tmp_goal.append(a)
    

    # 島1から意外の運航便のリスト
    #else:
    #    a_list.append([a, b])

agree = set(tmp_start) & set(tmp_goal)

if len(agree) == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

#for j in tmp_start:
#    if j in tmp_goal:
#        print('POSSIBLE')
#        break

#else:
#    print('IMPOSSIBLE')