@staticmethod
def d():
    (h, w) = map(int, sys.stdin.readline().split())
    s = sys.stdin.read().split()
    dyx = list(itertools.product(((- 1), 0, 1), repeat=2))
    black_certain = set()
    black_before = set()
    for i in range(h):
        for j in range(w):
            black_cand = set()
            for (dy, dx) in dyx:
                y = (i + dy)
                x = (j + dx)
                if ((y < 0) or (y >= h) or (x < 0) or (x >= w)):
                    continue
                if (s[y][x] == '.'):
                    break
                black_cand.add((y, x))
            else:
                black_before.add((i, j))
                black_certain |= black_cand
    for i in range(h):
        for j in range(w):
            if ((s[i][j] == '#') and (not ((i, j) in black_certain))):
                print('impossible')
                return
    print('possible')
    for i in range(h):
        row = ''
        for j in range(w):
            row += ('#' if ((i, j) in black_before) else '.')
        print(''.join(row))
@staticmethod
def d():
    (h, w) = map(int, sys.stdin.readline().split())
    s = sys.stdin.read().split()
    dyx = list(itertools.product(((- 1), 0, 1), repeat=2))
    black_certain = set()
    black_before = set()
    for i in range(h):
        for j in range(w):
            black_cand = set()
            for (dy, dx) in dyx:
                y = (i + dy)
                x = (j + dx)
                if ((y < 0) or (y >= h) or (x < 0) or (x >= w)):
                    continue
                if (s[y][x] == '.'):
                    break
                black_cand.add((y, x))
            else:
                black_before.add((i, j))
                black_certain |= black_cand
    for i in range(h):
        for j in range(w):
            if ((s[i][j] == '#') and (not ((i, j) in black_certain))):
                print('impossible')
                return
    print('possible')
    for i in range(h):
        row = 
        for j in range(w):
            row += ('#' if ((i, j) in black_before) else '.')
        print(.join(row))