H, W = list(map(int, input().split()))

matrix = []

hd = []

wd = []



for i in range(H):

    h = list(eval(input()))

    matrix.append(h)

    if h == ["."] * W:

        continue

    hd.append(i)



for i in range(W):

    w = [list(w_[i]) for w_ in matrix]

    if w == [["."]] * H:

        continue

    wd.append(i)



ansmatrix = []

row = []

for i in hd:

    for j in wd:

        row.append(matrix[i][j])

    ansmatrix.append(row)

    row = []



for ansrow in ansmatrix:

    print(("".join(ansrow)))
H, W = list(map(int, input().split()))

matrix = []

ans = []

for i in range(H):

    h = list(eval(input()))

    if "#" in h:

        matrix.append(h)

for j in range(W):

    w = [w_[j] for w_ in matrix]

    if "#" in w:

        ans.append(w)

for k in range(len(ans[0])):

    print(("".join([r[k] for r in ans])))
H, W = list(map(int, input().split()))
matrix = []
hd = []
wd = []
for i in range(H):
    h = list(eval(input()))
    matrix.append(h)
    if h == ["."] * W:
        continue
    hd.append(i)
for i in range(W):
    w = [list(w_[i]) for w_ in matrix]
    if w == [["."]] * H:
        continue
    wd.append(i)
ansmatrix = []
row = []
for i in hd:
    for j in wd:
        row.append(matrix[i][j])
    ansmatrix.append(row)
    row = []
for ansrow in ansmatrix:
    print(("".join(ansrow)))

H, W = list(map(int, input().split()))
matrix = []
ans = []
for i in range(H):
    h = list(eval(input()))
    if "#" in h:
        matrix.append(h)
for j in range(W):
    w = [w_[j] for w_ in matrix]
    if "#" in w:
        ans.append(w)
for k in range(len(ans[0])):
    print(("".join([r[k] for r in ans])))

-hd = [] -wd = [] +ans = [] -    matrix.append(h) -    if h == ["."] * W: -        continue -    hd.append(i) -for i in range(W): -    w = [list(w_[i]) for w_ in matrix] -    if w == [["."]] * H: -        continue -    wd.append(i) -ansmatrix = [] -row = [] -for i in hd: -    for j in wd: -        row.append(matrix[i][j]) -    ansmatrix.append(row) -    row = [] -for ansrow in ansmatrix: -    print(("".join(ansrow))) +    if "#" in h: +        matrix.append(h) +for j in range(W): +    w = [w_[j] for w_ in matrix] +    if "#" in w: +        ans.append(w) +for k in range(len(ans[0])): +    print(("".join([r[k] for r in ans])))