Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())
AB = []
for _ in range(M):
    a,b = map(int,input().split())
    if  a == 1 or b== N:
        AB.append((a,b))
AB = set(AB)
for ab in AB:
    if ab[0] == 1:
        for  cd in AB:
            if cd[1] == N and ab[1] == cd[0]:
                    print("POSSIBLE")
                    exit()
print("IMPOSSIBLE")

Fixed submission:
N, M = map(int,input().split())
AB = []
for _ in range(M):
    a,b = map(int,input().split())
    if  a == 1 or b== N:
        AB.append((a,b))
set1 = set()
set2 = set()
for ab in AB:
    if ab[0] == 1:
        set1.add(ab[1])
    if ab[1] == N:
        set2.add(ab[0])
if set1 & set2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())
AB = []
for _ in range(M):
    a,b = map(int,input().split())
    if  a == 1 or b== N:
        AB.append([a,b])
AB.sort()
for ab in AB:
    if ab[0] == 1:
        for  cd in AB:
            if cd[1] == N and ab[1] == cd[0]:
                    print("POSSIBLE")
                    exit()
print("IMPOSSIBLE")

Fixed submission:
N, M = map(int,input().split())
AB = []
for _ in range(M):
    a,b = map(int,input().split())
    if  a == 1 or b== N:
        AB.append((a,b))
set1 = set()
set2 = set()
for ab in AB:
    if ab[0] == 1:
        set1.add(ab[1])
    if ab[1] == N:
        set2.add(ab[0])
if set1 & set2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())
AB = []
for _ in range(M):
    a,b = map(int,input().split())
    if  a == 1 or b== N:
        AB.append([a,b])
AB.sort()
for ab in AB:
    if ab[0] == 1:
        for  cd in AB:
            if cd[1] == N and ab[1] == cd[0]:
                    print("POSSIBLE")
                    exit()
print("IMPOSSIBLE")

Fixed submission:
N, M = map(int,input().split())
AB = []
for _ in range(M):
    a,b = map(int,input().split())
    if  a == 1 or b== N:
        AB.append((a,b))
set1 = set()
set2 = set()
for ab in AB:
    if ab[0] == 1:
        set1.add(ab[1])
    if ab[1] == N:
        set2.add(ab[0])
if set1 & set2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
import copy
from operator import itemgetter
N, M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(M)]
mid = []
AB.sort()
CD = copy.deepcopy(AB)
CD = sorted(CD, key=itemgetter(1,0),reverse = True)
for ab in AB:
    if ab[0] == 1:
        for  cd in CD:
            if cd[1] == N:
                if ab[1] == cd[0]:
                    print("POSSIBLE")
                    exit()
            else:
                break
    else:
        break
print("IMPOSSIBLE")

Fixed submission:
N, M = map(int,input().split())
AB = []
for _ in range(M):
    a,b = map(int,input().split())
    if  a == 1 or b== N:
        AB.append((a,b))
set1 = set()
set2 = set()
for ab in AB:
    if ab[0] == 1:
        set1.add(ab[1])
    if ab[1] == N:
        set2.add(ab[0])
if set1 & set2:
    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)]
mid = []
AB.sort()
for ab in AB:
    if ab[0] == 1:
        for  cd in AB:
            if ab[1] == cd[0] and cd[1] == N:
                print("POSSIBLE")
                exit()
    else:
        break
print("IMPOSSIBLE")

Fixed submission:
N, M = map(int,input().split())
AB = []
for _ in range(M):
    a,b = map(int,input().split())
    if  a == 1 or b== N:
        AB.append((a,b))
set1 = set()
set2 = set()
for ab in AB:
    if ab[0] == 1:
        set1.add(ab[1])
    if ab[1] == N:
        set2.add(ab[0])
if set1 & set2:
    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)]
mid = []
AB.sort()
for ab in AB:
    if ab[0] == 1:
        for  cd in AB:
            if ab[1] == cd[0] and cd[1] == N:
                print("POSSIBLE")
                exit()
print("IMPOSSIBLE")

Fixed submission:
N, M = map(int,input().split())
AB = []
for _ in range(M):
    a,b = map(int,input().split())
    if  a == 1 or b== N:
        AB.append((a,b))
set1 = set()
set2 = set()
for ab in AB:
    if ab[0] == 1:
        set1.add(ab[1])
    if ab[1] == N:
        set2.add(ab[0])
if set1 & set2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")