Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
one_to = []
to_N = []
for _ in range(M):
    a,b = map(int,input().split())
    if a == 1:
        one_to.append(b)
    if b == N:
        to_N.append(a)
one_to.sort()
to_N.sort()
ans = 0 
for i in one_to:
    count = 0
    for j in range(len(to_N)):
        if i == to_N[j]:
            ans = 1
            break
        if i > to_N[j]:
            count += 1
        if i < to_N[j]:
            break
    to_N = to_N[count:]
    if ans == 1:
        break
if ans == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Fixed submission:
N,M = map(int,input().split())
ans = 0
dic = {str(i):0 for i in range(1,N)}
for _ in range(M):
    a,b = map(int,input().split())
    if a == 1:
        dic[str(b)] += 1
        if dic[str(b)] == 2:
            ans = 1
    if b == N:
        dic[str(a)] += 1
        if dic[str(a)] == 2:
            ans = 1
if ans == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
one_to = []
to_N = []
for _ in range(M):
    a,b = map(int,input().split())
    if a == 1:
        one_to.append(b)
    if b == N:
        to_N.append(a)
one_to.sort()
to_N.sort()
ans = 0 
for i in one_to:
    count = 0
    for j in range(len(to_N)):
        if i == to_N[j]:
            ans = 1
            break
        if i > to_N[j]:
            count += 1
        if i < to_N[j]:
            break
    to_N = to_N[count:]
    if ans == 1:
        break
if ans == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Fixed submission:
N,M = map(int,input().split())
ans = 0
dic = {str(i):0 for i in range(1,N)}
for _ in range(M):
    a,b = map(int,input().split())
    if a == 1:
        dic[str(b)] += 1
        if dic[str(b)] == 2:
            ans = 1
    if b == N:
        dic[str(a)] += 1
        if dic[str(a)] == 2:
            ans = 1
if ans == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
one_to = []
to_N = []
for _ in range(M):
    a,b = map(int,input().split())
    if a == 1:
        one_to.append(b)
    if b == N:
        to_N.append(a)
ans = 0 
for i in one_to:
    if i in to_N:
        ans = 1
        break
if ans == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Fixed submission:
N,M = map(int,input().split())
ans = 0
dic = {str(i):0 for i in range(1,N)}
for _ in range(M):
    a,b = map(int,input().split())
    if a == 1:
        dic[str(b)] += 1
        if dic[str(b)] == 2:
            ans = 1
    if b == N:
        dic[str(a)] += 1
        if dic[str(a)] == 2:
            ans = 1
if ans == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
one_to = []
to_N = []
for _ in range(M):
    a,b = map(int,input().split())
    if a == 1:
        one_to.append(b)
    if b == N:
        to_N.append(a)
ans = 0 
for i in one_to:
    if i in to_N:
        ans = 1
        break
if ans == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Fixed submission:
N,M = map(int,input().split())
ans = 0
dic = {str(i):0 for i in range(1,N)}
for _ in range(M):
    a,b = map(int,input().split())
    if a == 1:
        dic[str(b)] += 1
        if dic[str(b)] == 2:
            ans = 1
    if b == N:
        dic[str(a)] += 1
        if dic[str(a)] == 2:
            ans = 1
if ans == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')