Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

def main(N,M,to_,from_):
    ans = "IMPOSSIBLE"
    
    for to in to_:
        if to in from_:
            ans = "POSSIBLE"
            break
            
    print(ans)

if __name__ == '__main__':
    N, M = map(int, input().split())
    to_, from_ = [], []
    for i in range(M):
        a, b = map(int, input().split())
        if(a==1):
            to_.append(b)
        elif(b==N):
            from_.append(a)
    main(N,M,to_,from_)

Fixed submission:
# -*- coding: utf-8 -*-

def main(N,M,visited,queue):
    ans = "IMPOSSIBLE"

    for i in queue:
        if visited[i-1] == True:
            ans = "POSSIBLE"
            break
            
    print(ans)

if __name__ == '__main__':
    N, M = map(int, input().split())
    visited,queue = [False]*N, []
    for i in range(M):
        a, b = map(int, input().split())
        if(a==1):
            visited[b-1] = True
        elif(b==N):
            queue.append(a)
    main(N,M,visited,queue)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

def main(N,M,islands):
    queue = []
    flag = False
    for a,b in islands:
        if(a==1):
            queue.append(b)
    for a,b in islands:
        if(a in queue and b==N):
            flag = True
            break
            
    print("POSSIBLE") if flag else print("IMPOSSIBLE")

if __name__ == '__main__':
    N, M = map(int, input().split())
    islands = []
    for i in range(M):
        a, b = map(int, input().split())
        if(a==1 or b==N):
            islands.append([a,b])
    main(N,M,islands)

Fixed submission:
# -*- coding: utf-8 -*-

def main(N,M,visited,queue):
    ans = "IMPOSSIBLE"

    for i in queue:
        if visited[i-1] == True:
            ans = "POSSIBLE"
            break
            
    print(ans)

if __name__ == '__main__':
    N, M = map(int, input().split())
    visited,queue = [False]*N, []
    for i in range(M):
        a, b = map(int, input().split())
        if(a==1):
            visited[b-1] = True
        elif(b==N):
            queue.append(a)
    main(N,M,visited,queue)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

def main(N,M,islands):
    queue = []
    flag = False
    islands_s = sorted(islands, key=lambda x: x[0])
    islands_t = sorted(islands, key=lambda x: x[1], reverse=True)
    for a,b in islands_s:
        if(a==1):
            queue.append(b)
        else:
            break
    for a,b in islands_t:
        if(b!=N):
            break
        elif(a in queue and b==N):
            flag = True
            
    print("POSSIBLE") if flag else print("IMPOSSIBLE")

if __name__ == '__main__':
    N, M = map(int, input().split())
    islands = []
    for i in range(M):
        a, b = map(int, input().split())
        if(a==1 or b==N):
            islands.append([a,b])
    main(N,M,islands)

Fixed submission:
# -*- coding: utf-8 -*-

def main(N,M,visited,queue):
    ans = "IMPOSSIBLE"

    for i in queue:
        if visited[i-1] == True:
            ans = "POSSIBLE"
            break
            
    print(ans)

if __name__ == '__main__':
    N, M = map(int, input().split())
    visited,queue = [False]*N, []
    for i in range(M):
        a, b = map(int, input().split())
        if(a==1):
            visited[b-1] = True
        elif(b==N):
            queue.append(a)
    main(N,M,visited,queue)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

def main(N,M,islands):
    queue = []
    flag = False
    islands_s = sorted(islands, key=lambda x: x[0])
    for a,b in islands:
        if(a==1):
            queue.append(b)
    for a,b in islands:
        if(a in queue and b==N):
            flag = True
    print("POSSIBLE") if flag else print("IMPOSSIBLE")

if __name__ == '__main__':
    N, M = map(int, input().split())
    islands = []
    for i in range(M):
        a, b = map(int, input().split())
        islands.append([a,b])
    main(N,M,islands)

Fixed submission:
# -*- coding: utf-8 -*-

def main(N,M,visited,queue):
    ans = "IMPOSSIBLE"

    for i in queue:
        if visited[i-1] == True:
            ans = "POSSIBLE"
            break
            
    print(ans)

if __name__ == '__main__':
    N, M = map(int, input().split())
    visited,queue = [False]*N, []
    for i in range(M):
        a, b = map(int, input().split())
        if(a==1):
            visited[b-1] = True
        elif(b==N):
            queue.append(a)
    main(N,M,visited,queue)