Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations

h,w = map(int,input().split())
nec = []
for i in range(h):
    s = input()
    for j in range(w):
        if s[j] == "#":
            nec.append([i,j])

com = [1 for i in range(w-1)]+[0 for i in range(h-1)]
ans = False
alr = set()
for p in permutations(com):
    if p in alr:
        continue
    else:
        alr.add(p)
    # print(p)
    st = [0, 0]
    root = [[0, 0]]
    for c in p:
        if c == 1:
            nex = [st[0],st[1]+1]
            st = nex
            root.append(nex)
        else:
            nex = [st[0]+1,st[1]]
            st = nex
            root.append(nex)

    flags = [False for i in range(len(nec))]
    for i in range(len(nec)):
        if nec[i] in root:
            flags[i] = True
    # print(flags)
    ans = all(flags) or ans

if ans:
    print("Possible")
else:
    print("Impossible")


Fixed submission:
from itertools import permutations

h,w = map(int,input().split())
nec = []
for i in range(h):
    s = input()
    for j in range(w):
        if s[j] == "#":
            nec.append([i,j])

if len(nec) == h+w-1:
    print("Possible")
else:
    print("Impossible")

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations

h,w = map(int,input().split())
nec = []
for i in range(h):
    s = input()
    for j in range(w):
        if s[j] == "#":
            nec.append([i,j])

com = [1 for i in range(w-1)]+[0 for i in range(h-1)]
ans = False
alr = set()
for p in permutations(com):
    if p in alr:
        continue
    else:
        alr.add(p)
    # print(p)
    st = [0, 0]
    root = [[0, 0]]
    for c in p:
        if c == 1:
            nex = [st[0],st[1]+1]
            st = nex
            root.append(nex)
        else:
            nex = [st[0]+1,st[1]]
            st = nex
            root.append(nex)

    flags = [False for i in range(len(nec))]
    for i in range(len(nec)):
        if nec[i] in root:
            flags[i] = True
    # print(flags)
    ans = all(flags) or ans

if ans:
    print("Possible")
else:
    print("Impossible")


Fixed submission:
from itertools import permutations

h,w = map(int,input().split())
nec = []
for i in range(h):
    s = input()
    for j in range(w):
        if s[j] == "#":
            nec.append([i,j])

if len(nec) == h+w-1:
    print("Possible")
else:
    print("Impossible")

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations

h,w = map(int,input().split())
nec = []
for i in range(h):
    s = input()
    for j in range(w):
        if s[j] == "#":
            nec.append([i,j])

com = [1 for i in range(w-1)]+[0 for i in range(h-1)]
ans = False
for p in permutations(com):
    # print(p)
    st = [0, 0]
    root = [[0, 0]]
    for c in p:
        if c == 1:
            nex = [st[0],st[1]+1]
            st = nex
            root.append(nex)
        else:
            nex = [st[0]+1,st[1]]
            st = nex
            root.append(nex)

    flags = [False for i in range(len(nec))]
    for i in range(len(nec)):
        if nec[i] in root:
            flags[i] = True
    # print(flags)
    ans = all(flags) or ans

if ans:
    print("Possible")
else:
    print("Impossible")


Fixed submission:
from itertools import permutations

h,w = map(int,input().split())
nec = []
for i in range(h):
    s = input()
    for j in range(w):
        if s[j] == "#":
            nec.append([i,j])

if len(nec) == h+w-1:
    print("Possible")
else:
    print("Impossible")