Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import os
from collections import OrderedDict, deque
from bisect import bisect_left, bisect_right, insort_left, insort_right


class EndLoop(Exception):
    pass


def solve():
    while 1:
        try:
            N, M = list(map(int, input().split(" ")))
            Deque1 = deque()
            DequeN = deque()
            edges_1 = [None] * N
            edges_N = [None] * N
            Deque1.extend(edges_1)
            DequeN.extend(edges_N)

            for _ in range(M):
                a, b = list(map(int, input().split(" ")))
                if a == 1:
                    Deque1[b - 1] = True
                elif b == 1:
                    Deque1[a - 1] = True
                elif a == N:
                    DequeN[b - 1] = True
                elif b == N:
                    DequeN[a - 1] = True
                else:
                    pass

            for i in range(N):
                if Deque1[i] == True and DequeN[i] == True:
                    print("POSSIBLE")
                    raise EndLoop

            print("IMPOSSIBLE")
            break
        except:
            break


solve()

Fixed submission:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from collections import deque


class EndLoop(Exception):
    pass


def solve():
    while 1:
        try:
            N, M = list(map(int, input().split(" ")))
            Deque1 = deque()
            DequeN = deque()
            edges_1 = [False] * N
            edges_N = [False] * N
            Deque1.extend(edges_1)
            DequeN.extend(edges_N)

            for _ in range(M):
                a, b = list(map(int, input().split(" ")))
                if a == 1:
                    Deque1[b - 1] = True
                elif b == 1:
                    Deque1[a - 1] = True
                elif a == N:
                    DequeN[b - 1] = True
                elif b == N:
                    DequeN[a - 1] = True
                else:
                    pass

            for i in range(N):
                if Deque1[i] == True and DequeN[i] == True:
                    print("POSSIBLE")
                    raise EndLoop

            print("IMPOSSIBLE")
            break
        except:
            break


solve()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import os
from collections import OrderedDict, deque

def solve():
    while 1:
        try:
            N, M = list(map(int, input().split(" ")))
            Deque1 = deque()
            DequeN = deque()
            edges_1 = [False] * N
            edges_N = [False] * N
            Deque1.extend(edges_1)
            DequeN.extend(edges_N)

            for _ in range(M):
                a, b = list(map(int, input().split(" ")))
                if a == 1:
                    Deque1[b - 1] = True
                elif b == 1:
                    Deque1[a - 1] = True
                elif a == N:
                    DequeN[b - 1] = True
                elif b == N:
                    DequeN[a - 1] = True
                else:
                    pass

            for i in range(N):
                if Deque1[i] == True and DequeN[i] == True:
                    print("POSSIBLE")
                    raise EndLoop

            print("IMPOSSIBLE")
            break
        except:
            break


solve()

Fixed submission:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from collections import deque


class EndLoop(Exception):
    pass


def solve():
    while 1:
        try:
            N, M = list(map(int, input().split(" ")))
            Deque1 = deque()
            DequeN = deque()
            edges_1 = [False] * N
            edges_N = [False] * N
            Deque1.extend(edges_1)
            DequeN.extend(edges_N)

            for _ in range(M):
                a, b = list(map(int, input().split(" ")))
                if a == 1:
                    Deque1[b - 1] = True
                elif b == 1:
                    Deque1[a - 1] = True
                elif a == N:
                    DequeN[b - 1] = True
                elif b == N:
                    DequeN[a - 1] = True
                else:
                    pass

            for i in range(N):
                if Deque1[i] == True and DequeN[i] == True:
                    print("POSSIBLE")
                    raise EndLoop

            print("IMPOSSIBLE")
            break
        except:
            break


solve()

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    while 1:
        try:
            N, M = list(map(int, input().split(" ")))
            graph = [[None] * N for _ in range(N)]
            for _ in range(M):
                a, b = list(map(int, input().split(" ")))
                graph[a - 1][b - 1], graph[b - 1][a - 1] = 1, 1

            edges_from1 = graph[0].count(1)
            edges_fromN = graph[N - 1].count(1)
            if not edges_from1 or not edges_fromN:
                print("IMPOSSIBLE")
                break

            if edges_fromN < edges_from1:
                start_node = N - 1
                goal_node = 0
            else:
                start_node = 0
                goal_node = N - 1

            for j in range(N):
                if graph[start_node][j] == 1:
                    if graph[j][goal_node] == 1:
                        print("POSSIBLE")
                        raise EndLoop

            print("IMPOSSIBLE")
        except:
            break


solve()

Fixed submission:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from collections import deque


class EndLoop(Exception):
    pass


def solve():
    while 1:
        try:
            N, M = list(map(int, input().split(" ")))
            Deque1 = deque()
            DequeN = deque()
            edges_1 = [False] * N
            edges_N = [False] * N
            Deque1.extend(edges_1)
            DequeN.extend(edges_N)

            for _ in range(M):
                a, b = list(map(int, input().split(" ")))
                if a == 1:
                    Deque1[b - 1] = True
                elif b == 1:
                    Deque1[a - 1] = True
                elif a == N:
                    DequeN[b - 1] = True
                elif b == N:
                    DequeN[a - 1] = True
                else:
                    pass

            for i in range(N):
                if Deque1[i] == True and DequeN[i] == True:
                    print("POSSIBLE")
                    raise EndLoop

            print("IMPOSSIBLE")
            break
        except:
            break


solve()

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    while 1:
        try:
            N, M = list(map(int, input().split(" ")))
            graph = [[0] * N for _ in range(N)]
            for _ in range(M):
                a, b = list(map(int, input().split(" ")))
                graph[a - 1][b - 1], graph[b - 1][a - 1] = 1, 1

            edges_from1 = graph[0].count(1)
            edges_fromN = graph[N - 1].count(1)
            if not edges_from1 or not edges_fromN:
                print("IMPOSSIBLE")
                break

            if edges_from1 < edges_fromN:
                start_node = 0
                goal_node = N - 1
            elif edges_fromN < edges_from1:
                start_node = N - 1
                goal_node = 0
            else:
                start_node = 0
                goal_node = N - 1

            for j in range(N):
                if graph[start_node][j] == 1:
                    if graph[j][goal_node] == 1:
                        print("POSSIBLE")
                        raise EndLoop

            print("IMPOSSIBLE")
        except:
            break


solve()

Fixed submission:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from collections import deque


class EndLoop(Exception):
    pass


def solve():
    while 1:
        try:
            N, M = list(map(int, input().split(" ")))
            Deque1 = deque()
            DequeN = deque()
            edges_1 = [False] * N
            edges_N = [False] * N
            Deque1.extend(edges_1)
            DequeN.extend(edges_N)

            for _ in range(M):
                a, b = list(map(int, input().split(" ")))
                if a == 1:
                    Deque1[b - 1] = True
                elif b == 1:
                    Deque1[a - 1] = True
                elif a == N:
                    DequeN[b - 1] = True
                elif b == N:
                    DequeN[a - 1] = True
                else:
                    pass

            for i in range(N):
                if Deque1[i] == True and DequeN[i] == True:
                    print("POSSIBLE")
                    raise EndLoop

            print("IMPOSSIBLE")
            break
        except:
            break


solve()

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    while 1:
        try:
            N, M = list(map(int, input().split(" ")))
            graph = [[0] * N for _ in range(N)]
            for _ in range(M):
                a, b = list(map(int, input().split(" ")))
                graph[a - 1][b - 1], graph[b - 1][a - 1] = 1, 1

            edges_from1 = graph[0].count(1)
            edges_fromN = graph[N - 1].count(1)
            if not edges_from1 or not edges_fromN:
                print("IMPOSSIBLE")
                break

            if edges_from1 < edges_fromN:
                start_node = 0
                goal_node = N - 1
            elif edges_fromN < edges_from1:
                start_node = N - 1
                goal_node = 0
            else:
                start_node = 0
                goal_node = N - 1

            for j in range(N):
                if graph[start_node][j] == 1:
                    if graph[j][goal_node] == 1:
                        print("POSSIBLE")
                        raise EndLoop

            print("IMPOSSIBLE")
        except:
            break


solve()

Fixed submission:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from collections import deque


class EndLoop(Exception):
    pass


def solve():
    while 1:
        try:
            N, M = list(map(int, input().split(" ")))
            Deque1 = deque()
            DequeN = deque()
            edges_1 = [False] * N
            edges_N = [False] * N
            Deque1.extend(edges_1)
            DequeN.extend(edges_N)

            for _ in range(M):
                a, b = list(map(int, input().split(" ")))
                if a == 1:
                    Deque1[b - 1] = True
                elif b == 1:
                    Deque1[a - 1] = True
                elif a == N:
                    DequeN[b - 1] = True
                elif b == N:
                    DequeN[a - 1] = True
                else:
                    pass

            for i in range(N):
                if Deque1[i] == True and DequeN[i] == True:
                    print("POSSIBLE")
                    raise EndLoop

            print("IMPOSSIBLE")
            break
        except:
            break


solve()