Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
edge = []
p = 'POSSIBLE'
i = 'IMPOSSIBLE'
for _ in range(M):
    edge.append(tuple(map(int,input().split())))

from1 = []
is_reach = False
for go,to in sorted(edge,key=lambda x:x[0]):
    if go == 1:
        from1.append(to)
    else:
        if go in from1 and to == N:
            is_reach = True
            break
print(p if is_reach else i)

Fixed submission:
N,M = map(int,input().split())
edge = []
p = 'POSSIBLE'
i = 'IMPOSSIBLE'
for _ in range(M):
    edge.append(tuple(map(int,input().split())))

from1 = set()
is_reach = False
for go,to in sorted(edge,key=lambda x:x[0]):
    if go == 1:
        from1.add(to)
    else:
        if go in from1 and to == N:
            is_reach = True
            break
print(p if is_reach else i)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
edge = []
p = 'POSSIBLE'
i = 'IMPOSSIBLE'
for _ in range(M):
    edge.append(list(map(int,input().split())))

from1 = []
is_reach = False
for go,to in sorted(edge,key=lambda x:x[0]):
    if go == 1:
        from1.append(to)
    else:
        if go in from1 and to == N:
            is_reach = True
            break
print(p if is_reach else i)

Fixed submission:
N,M = map(int,input().split())
edge = []
p = 'POSSIBLE'
i = 'IMPOSSIBLE'
for _ in range(M):
    edge.append(tuple(map(int,input().split())))

from1 = set()
is_reach = False
for go,to in sorted(edge,key=lambda x:x[0]):
    if go == 1:
        from1.add(to)
    else:
        if go in from1 and to == N:
            is_reach = True
            break
print(p if is_reach else i)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
edge = [[] for _ in range(N+1)]
for i in range(M):
    go,to = map(int,input().split())
    edge[go].append(to)
    edge[to].append(go)
count = [0 for _ in range(N+1)]
stack = [[N,0]]
count[N] = 1
ok = False
for i in range(2*M):
    if stack == []:
        break
    arr = stack.pop(0)
    if arr[1] < 3:
        if arr[0] == 1:
            ok = True
            break
        else:
            for i in edge[arr[0]]:
                if count[i] == 0:
                    stack.append([i,arr[1]+1])
                    count[i] = 1
print('POSSIBLE' if ok else 'IMPOSSIBLE')    

Fixed submission:
N,M = map(int,input().split())
edge = []
p = 'POSSIBLE'
i = 'IMPOSSIBLE'
for _ in range(M):
    edge.append(tuple(map(int,input().split())))

from1 = set()
is_reach = False
for go,to in sorted(edge,key=lambda x:x[0]):
    if go == 1:
        from1.add(to)
    else:
        if go in from1 and to == N:
            is_reach = True
            break
print(p if is_reach else i)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
edge = [[] for _ in range(N+1)]
for i in range(M):
    go,to = map(int,input().split())
    edge[go].append(to)
    edge[to].append(go)
count = [0 for _ in range(N+1)]
stack = [[N,0]]
count[N] = 1
ok = False
for i in range(2*M):
    if stack == []:
        break
    arr = stack.pop(0)
    if arr[1] < 3:
        if arr[0] == 1:
            ok = True
            break
        else:
            for i in edge[arr[0]]:
                if count[i] == 0:
                    stack.append([i,arr[1]+1])
                    count[i] = 1
print('POSSIBLE' if ok else 'IMPOSSIBLE')    

Fixed submission:
N,M = map(int,input().split())
edge = []
p = 'POSSIBLE'
i = 'IMPOSSIBLE'
for _ in range(M):
    edge.append(tuple(map(int,input().split())))

from1 = set()
is_reach = False
for go,to in sorted(edge,key=lambda x:x[0]):
    if go == 1:
        from1.add(to)
    else:
        if go in from1 and to == N:
            is_reach = True
            break
print(p if is_reach else i)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
edge = [[] for _ in range(N+1)]
for i in range(M):
    go,to = map(int,input().split())
    edge[go].append(to)
    edge[to].append(go)
count = 0
stack = [[N,0]]
ok = False
for i in range(2*M):
    if stack == []:
        break
    arr = stack.pop(0)
    if arr[1] < 3:
        if arr[0] == 1:
            ok = True
            break
        else:
            for i in edge[arr[0]]:
                stack.append([i,arr[1]+1])
print('POSSIBLE' if ok else 'IMPOSSIBLE')    

Fixed submission:
N,M = map(int,input().split())
edge = []
p = 'POSSIBLE'
i = 'IMPOSSIBLE'
for _ in range(M):
    edge.append(tuple(map(int,input().split())))

from1 = set()
is_reach = False
for go,to in sorted(edge,key=lambda x:x[0]):
    if go == 1:
        from1.add(to)
    else:
        if go in from1 and to == N:
            is_reach = True
            break
print(p if is_reach else i)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
edge = [[] for _ in range(N+1)]
for i in range(M):
    go,to = map(int,input().split())
    edge[go].append(to)
    edge[to].append(go)
count = 0
stack = [[N,0]]
ok = False
for i in range(2*M):
    if stack == []:
        break
    arr = stack.pop(0)
    if arr[1] < 3:
        if arr[0] == 1:
            ok = True
            break
        else:
            for i in edge[arr[0]]:
                stack.append([i,arr[1]+1])
print('POSSIBLE' if ok else 'IMPOSSIBLE')    

Fixed submission:
N,M = map(int,input().split())
edge = []
p = 'POSSIBLE'
i = 'IMPOSSIBLE'
for _ in range(M):
    edge.append(tuple(map(int,input().split())))

from1 = set()
is_reach = False
for go,to in sorted(edge,key=lambda x:x[0]):
    if go == 1:
        from1.add(to)
    else:
        if go in from1 and to == N:
            is_reach = True
            break
print(p if is_reach else i)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
edge = [[] for _ in range(N+1)]
for i in range(M):
    go,to = map(int,input().split())
    edge[go].append(to)
    edge[to].append(go)
count = 0
stack = [[N,0]]
ok = False
while(stack != []):
    arr = stack.pop(0)
    if arr[1] < 3:
        if arr[0] == 1:
            ok = True
            break
        else:
            for i in edge[arr[0]]:
                stack.append([i,arr[1]+1])
print('POSSIBLE' if ok else 'IMPOSSIBLE')    

Fixed submission:
N,M = map(int,input().split())
edge = []
p = 'POSSIBLE'
i = 'IMPOSSIBLE'
for _ in range(M):
    edge.append(tuple(map(int,input().split())))

from1 = set()
is_reach = False
for go,to in sorted(edge,key=lambda x:x[0]):
    if go == 1:
        from1.add(to)
    else:
        if go in from1 and to == N:
            is_reach = True
            break
print(p if is_reach else i)