h, w = list(map(int, input().split()))



rows = [] #最初のfor文で、..だけの行を除く行を格納



for i in range(h):

  row = eval(input())

  for c in row:

    if c == '#':

      rows.append(row)

      break

      

columns = []

column = ''

for i in range(w): #各列に対して行う

  for j in range(len(rows)): #行の数、つまり列の長さ

    if rows[j][i:i+1] == '#':

      for k in range(len(rows)):

        column += rows[k][i:i+1]

      columns.append(column)

      column = ''

      break

      

r = len(columns[0]) #最終行の数

ansrows = [''] * r

for i in range(r): #最終行の数だけ

  for j in range(len(columns)): #最終列の数だけ

  	ansrows[i] += columns[j][i]



#解答

for ans in ansrows: print(ans)
h, w = list(map(int, input().split()))

rs = [eval(input()) for _ in range(h)]

rows = []



#.だけの行を省いてrowsに格納

for r in rs:

  if '#' in r: rows.append(r)



ansrows = list(zip(*[c for c in zip(*rows) if '#' in c]))



for r in list(ansrows):

  print((''.join(r)))
h, w = list(map(int, input().split()))
rows = []  # 最初のfor文で、..だけの行を除く行を格納
for i in range(h):
    row = eval(input())
    for c in row:
        if c == "#":
            rows.append(row)
            break
columns = []
column = ""
for i in range(w):  # 各列に対して行う
    for j in range(len(rows)):  # 行の数、つまり列の長さ
        if rows[j][i : i + 1] == "#":
            for k in range(len(rows)):
                column += rows[k][i : i + 1]
            columns.append(column)
            column = ""
            break
r = len(columns[0])  # 最終行の数
ansrows = [""] * r
for i in range(r):  # 最終行の数だけ
    for j in range(len(columns)):  # 最終列の数だけ
        ansrows[i] += columns[j][i]
# 解答
for ans in ansrows:
    print(ans)

h, w = list(map(int, input().split()))
rs = [eval(input()) for _ in range(h)]
rows = []
# .だけの行を省いてrowsに格納
for r in rs:
    if "#" in r:
        rows.append(r)
ansrows = list(zip(*[c for c in zip(*rows) if "#" in c]))
for r in list(ansrows):
    print(("".join(r)))

-rows = []  # 最初のfor文で、..だけの行を除く行を格納 -for i in range(h): -    row = eval(input()) -    for c in row: -        if c == "#": -            rows.append(row) -            break -columns = [] -column = "" -for i in range(w):  # 各列に対して行う -    for j in range(len(rows)):  # 行の数、つまり列の長さ -        if rows[j][i : i + 1] == "#": -            for k in range(len(rows)): -                column += rows[k][i : i + 1] -            columns.append(column) -            column = "" -            break -r = len(columns[0])  # 最終行の数 -ansrows = [""] * r -for i in range(r):  # 最終行の数だけ -    for j in range(len(columns)):  # 最終列の数だけ -        ansrows[i] += columns[j][i] -# 解答 -for ans in ansrows: -    print(ans) +rs = [eval(input()) for _ in range(h)] +rows = [] +# .だけの行を省いてrowsに格納 +for r in rs: +    if "#" in r: +        rows.append(r) +ansrows = list(zip(*[c for c in zip(*rows) if "#" in c])) +for r in list(ansrows): +    print(("".join(r)))