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

A=[eval(input()) for i in range(H)]



B=[]

D=[]



for i in range(H):

  if A[i]!="."*W:

    B.append(list(A[i]))

    

C=[["0" for j in range(len(B))] for i in range(W)]



for i in range(len(B)):

  for j in range(W):

    C[j][i]=B[i][j]



for i in range(W):

  if C[i]!=["."]*len(B):

    D.append(C[i])

   

E=[["0" for j in range(len(D))] for i in range(len(B))]



for i in range(len(D)):

  for j in range(len(B)):

    E[j][i]=D[i][j]

    

for i in range(len(B)):

  print(("".join(E[i])))



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

A=[list(eval(input())) for i in range(H)]



for i in reversed(list(range(H))):

  if A[i]==["."]*W:

    A.pop(i)

    

for j in reversed(list(range(W))):

  flag=0

  for i in range(len(A)):

    if A[i][j]=="#":

      flag=1

  if flag==0:

    for i in range(len(A)):

      A[i].pop(j)



for i in range(len(A)):

	print(("".join(A[i])))
H, W = list(map(int, input().split()))
A = [eval(input()) for i in range(H)]
B = []
D = []
for i in range(H):
    if A[i] != "." * W:
        B.append(list(A[i]))
C = [["0" for j in range(len(B))] for i in range(W)]
for i in range(len(B)):
    for j in range(W):
        C[j][i] = B[i][j]
for i in range(W):
    if C[i] != ["."] * len(B):
        D.append(C[i])
E = [["0" for j in range(len(D))] for i in range(len(B))]
for i in range(len(D)):
    for j in range(len(B)):
        E[j][i] = D[i][j]
for i in range(len(B)):
    print(("".join(E[i])))

H, W = list(map(int, input().split()))
A = [list(eval(input())) for i in range(H)]
for i in reversed(list(range(H))):
    if A[i] == ["."] * W:
        A.pop(i)
for j in reversed(list(range(W))):
    flag = 0
    for i in range(len(A)):
        if A[i][j] == "#":
            flag = 1
    if flag == 0:
        for i in range(len(A)):
            A[i].pop(j)
for i in range(len(A)):
    print(("".join(A[i])))

-A = [eval(input()) for i in range(H)] -B = [] -D = [] -for i in range(H): -    if A[i] != "." * W: -        B.append(list(A[i])) -C = [["0" for j in range(len(B))] for i in range(W)] -for i in range(len(B)): -    for j in range(W): -        C[j][i] = B[i][j] -for i in range(W): -    if C[i] != ["."] * len(B): -        D.append(C[i]) -E = [["0" for j in range(len(D))] for i in range(len(B))] -for i in range(len(D)): -    for j in range(len(B)): -        E[j][i] = D[i][j] -for i in range(len(B)): -    print(("".join(E[i]))) +A = [list(eval(input())) for i in range(H)] +for i in reversed(list(range(H))): +    if A[i] == ["."] * W: +        A.pop(i) +for j in reversed(list(range(W))): +    flag = 0 +    for i in range(len(A)): +        if A[i][j] == "#": +            flag = 1 +    if flag == 0: +        for i in range(len(A)): +            A[i].pop(j) +for i in range(len(A)): +    print(("".join(A[i])))