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

a=[]

for _ in range(H):

  a.append(list([1 if x=="#" else 0 for x in list(eval(input()))]))

#print(a)



b=[]

for i in range(H):

  if sum(a[i])!=0:

    b.append(a[i])

#print(b)



c=[]

for j in range(W):

  cnt=0

  for i in range(len(b)):

    cnt+=b[i][j]

  c.append(cnt)

#print(c)



d=[]

for i in range(len(b)):

  dd=[]

  for j in range(W):

    if c[j]!=0:

      dd.append(b[i][j])

  d.append(dd)

#print(d)



for i in range(len(d)):

  print(("".join(list(["." if x==0 else "#" for x in d[i]]))))
H, W = list(map(int, input().split()))

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



h_check = [0] * H

w_check = [0] * W



for i in range(H):

  flag = 0

  for j in range(W):

    if A[i][j] != ".":

      flag = 1

      break

  h_check[i] = flag



for j in range(W):

  flag = 0

  for i in range(H):

    if A[i][j] != ".":

      flag = 1

      break

  w_check[j] = flag



for i in range(H):

  if h_check[i]:

    tmp = ""

    for j in range(W):

      if w_check[j]:

        tmp += A[i][j]

    print(tmp)
H, W = list(map(int, input().split()))
a = []
for _ in range(H):
    a.append(list([1 if x == "#" else 0 for x in list(eval(input()))]))
# print(a)
b = []
for i in range(H):
    if sum(a[i]) != 0:
        b.append(a[i])
# print(b)
c = []
for j in range(W):
    cnt = 0
    for i in range(len(b)):
        cnt += b[i][j]
    c.append(cnt)
# print(c)
d = []
for i in range(len(b)):
    dd = []
    for j in range(W):
        if c[j] != 0:
            dd.append(b[i][j])
    d.append(dd)
# print(d)
for i in range(len(d)):
    print(("".join(list(["." if x == 0 else "#" for x in d[i]]))))

H, W = list(map(int, input().split()))
A = [eval(input()) for _ in range(H)]
h_check = [0] * H
w_check = [0] * W
for i in range(H):
    flag = 0
    for j in range(W):
        if A[i][j] != ".":
            flag = 1
            break
    h_check[i] = flag
for j in range(W):
    flag = 0
    for i in range(H):
        if A[i][j] != ".":
            flag = 1
            break
    w_check[j] = flag
for i in range(H):
    if h_check[i]:
        tmp = ""
        for j in range(W):
            if w_check[j]:
                tmp += A[i][j]
        print(tmp)

-a = [] -for _ in range(H): -    a.append(list([1 if x == "#" else 0 for x in list(eval(input()))])) -# print(a) -b = [] +A = [eval(input()) for _ in range(H)] +h_check = [0] * H +w_check = [0] * W -    if sum(a[i]) != 0: -        b.append(a[i]) -# print(b) -c = [] +    flag = 0 +    for j in range(W): +        if A[i][j] != ".": +            flag = 1 +            break +    h_check[i] = flag -    cnt = 0 -    for i in range(len(b)): -        cnt += b[i][j] -    c.append(cnt) -# print(c) -d = [] -for i in range(len(b)): -    dd = [] -    for j in range(W): -        if c[j] != 0: -            dd.append(b[i][j]) -    d.append(dd) -# print(d) -for i in range(len(d)): -    print(("".join(list(["." if x == 0 else "#" for x in d[i]])))) +    flag = 0 +    for i in range(H): +        if A[i][j] != ".": +            flag = 1 +            break +    w_check[j] = flag +for i in range(H): +    if h_check[i]: +        tmp = "" +        for j in range(W): +            if w_check[j]: +                tmp += A[i][j] +        print(tmp)