There is a grid of squares with H horizontal rows and W vertical columns.
The square at the i-th row from the top and the j-th column from the left is represented as (i, j).
Each square is black or white.
The color of the square is given as an H-by-W matrix (a_{i, j}).
If a_{i, j} is ., the square (i, j) is white; if a_{i, j} is #, the square (i, j) is black.
Snuke is compressing this grid.
He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:
 - Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.
It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation.
Find the final state of the grid.

-----Constraints-----
 - 1 \leq H, W \leq 100
 - a_{i, j} is . or #.
 - There is at least one black square in the whole grid.

-----Input-----
Input is given from Standard Input in the following format:
H W
a_{1, 1}...a_{1, W}
:
a_{H, 1}...a_{H, W}

-----Output-----
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity.

-----Sample Input-----
4 4
##.#
....
##.#
.#.#

-----Sample Output-----
###
###
.##

The second row and the third column in the original grid will be removed.

Difficulty: introductory

Starter code:

Solutions:
h,w = map(int, input().split())
cell = []

for i in range(h):
    row = list(input())
    if row != ["."]*w:
        cell.append(row)

counter = []
for i in range(w):
    flag = 0
    for j in range(len(cell)):
        if cell[j][i] == "#":
            flag = 1
            break
    if flag == 1:
            counter.append(i)

for a in cell:
    ans = ''
    for i in counter:
        ans = ans + a[i]
    print(ans)

import numpy as np
H, W = map(int, input().split())
mat = []
for _ in range(H):
    a = list(input())
    ca = [0 if i == '.' else 1 for i in a]
    mat.append(ca)
amat = np.array(mat)

mask1 = []
for i in range(H):
    if np.sum(amat[i]) != 0:
        mask1.append(i)
amat1 = amat[mask1]

mask2 = []
for i in range(W):
    if np.sum(amat1[:,i]) != 0:
        mask2.append(i)
amat2 = amat1[:,mask2]

ans = []
for i in range(amat2.shape[0]):
    temp = ''
    for s in amat2[i]:
        if s == 1:
            temp += '#'
        else:
            temp += '.'
    ans.append(temp)
print(*ans, sep='\n')


H, W = list(map(int, input().split()))
a = []
for i in range(H):
    s = input()
    if "#" in s:
        a.append(s)

d = [i for i in range(W)]

for i in range(W):
    f = 0
    for j in a:
        if j[i] == "#":
            f = 1
            break
    if f == 0:
        d.remove(i)

ans = [""] * H
for i in range(len(a)):
    for j in d:
        ans[i] += a[i][j]
    print((ans[i]))



h,w = map(int, input().split())
ab = list(input() for _ in range(h))

res =[]

for i in range(h):
    if ab[i].count(".") ==w:
        pass
    else:
        res.append(ab[i])

l = len(res)

ress=[]
for j in range(w):
    b = list(map(lambda x: x[j], res))
    if b.count(".") ==l:
        pass
    else:
        ress.append(b)

ans = list(zip(*ress))

for i in range(l):
    print(''.join(ans[i]))

import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

ignore = "".join(["." for _ in range(W)])

A = list([x for x in [input() for _ in range(H)] if x != ignore])
H = len(A)
B = [[] for _ in range(H)]

for w in range(W):
    if list([x for x in A if x[w] == "#"]):
        for i in range(H):
            B[i].append(A[i][w])

for h in range(H):
    print(("".join(B[h])))


n, m = map(int, input().split())  
mat = []
for i in range(n):
    s = list(input())
    if '#' in s:
        mat.append(s)
mat2 = []
for i in range(m):
    s = [mat[x][i] for x in range(len(mat))]
    if '#' in s:
        mat2.append(s)

for i in range(len(mat2[0])):
    s = ''
    for x in range(len(mat2)):
        s += mat2[x][i]
    print(s)

import numpy as np

h,w = map(int,input().split())
a = [list(str(input())) for i in range(h)]

ans = np.array(a)
cnt = 0
for i,grid in enumerate(a):
    if '#' not in grid:
        ans = np.delete(ans,i-cnt,0)
        cnt += 1 


cnt = 0
for i in range(w):
    for j,grid in enumerate(a):
        if grid[i] == '#':
            break
    else:
        ans = np.delete(ans,i-cnt,1)
        cnt += 1

for i in range(len(ans)):
    print(''.join(ans[i]))

h,w=map(int,input().split())
A=[list(input()) for i in range(h)]
answ=[]
ansh=[]
for i in range(h):
  if not all([a=="." for a in A[i]]):
    answ.append(i)
for j in range(w):
  if not all([A[i][j]=="." for i in range(h)]):
    ansh.append(j)
for i in answ:
  for j in ansh:
    print(A[i][j],end="")
  print("")

h, w = map(int, input().split())
a = [i for i in [input() for i in range(h)] if "#" in i]
a = [i for i in zip(*a) if "#" in i]
for i in zip(*a):
  print("".join(i))

import sys
import copy
import math
import itertools
import numpy as np

H,W = [int(c) for c in input().split()]
a = np.array([list(input()) for c in range(H)])
b = copy.deepcopy(a)
Hc=[]
Wc=[]
for i in range(H):
    if np.count_nonzero(a[i,:] == ".") == W:
        Hc.append(i)

for i in range(W):
    if np.count_nonzero(a[:,i] == ".") == H:
        Wc.append(i)

a = np.delete(a,Hc,0)
a = np.delete(a,Wc,1)

for i in range(len(a)):
    s = ""
    for j in range(len(a[i])):
        s+=a[i][j]
    print(s)

h,w=map(int,input().split())
A=[list(input()) for i in range(h)]
answ=[]
ansh=[]
for i in range(h):
  if not all([a=="." for a in A[i]]):
    answ.append(i)
for j in range(w):
  if not all([A[i][j]=="." for i in range(h)]):
    ansh.append(j)
for i in answ:
  for j in ansh:
    print(A[i][j],end="")
  print("\n")
    

import numpy as np
H, W = map(int, input().split())
a = ['']*H
for i in range(H):
  a[i] = input()

h_flag = [0]*H
w_flag = [0]*W
for iHeight in range(H):
  for jWidth in range(W):
    if a[iHeight][jWidth] == '#':
      h_flag[iHeight] = 1
      w_flag[jWidth] = 1

for iHeight in range(H):
  if h_flag[iHeight] == 1:
    for jWidth in range(W):
      if w_flag[jWidth] == 1:
        print(a[iHeight][jWidth], end='')
    print()

h,w =  map(int,input().split())
mat = [input() for i in range(h)]
n = 0
max = h
while n<max:
    if mat[n]=="."*w:
        mat.pop(n)
        n -= 1
        max -= 1
    n += 1
flag = [True for i in range(w)]
for i in mat:
    for j in range(w):
        if i[j]=="#":
            flag[j] = False
ans = []
for i in mat:
    temp = ""
    for j in range(w):
        if not flag[j]:
            temp += i[j]
    ans.append(temp)
for i in ans:
    print(i)

H,W=map(int,input().split())
L=[[] for i in range(H)]
yoko=list()
for i in range(H):
  L1=list(input())
  if L1==["."]*W:
    yoko.append(i)
  L[i]=L1
R=list(range(W))
for i in range(H):
  for j in range(W):
    if j in R and L[i][j]=="#":
      R.remove(j)
for i in range(H):
  if i in yoko:
    continue
  s=L[i]
  r=list()
  for j in range(W):
    if j not in R:
      r.append(s[j])
  print("".join(r))

h, w = map(int, input().split())
a = []

for i in range(h):
    r = list(input())
    if '#' in r:
        a.append(r)

box = [0] * w

for colum in range(w):
    if all(row[colum] == '.' for row in a) :
        box[colum] = 1

for j in range(w):
    if box[j] == 1:
        for row in a:
            row[j] = ''

for row in a:
    print(''.join(map(str, row)))

H, W = map(int, input().split())
A = []
for i in range(H):
    x = input()
    if x.count('#') == 0:
        continue
    A.append(x)

c = set()
for a in A:
    for i in range(W):
        if a[i] == '#':
            c.add(i)

for a in A:
    for i in range(W):
        if i in c:
            print(a[i], end='')
    print()


import copy
h,w = map(int,input().split())
a = [input() for  i in range(h)]
index = 1
ans = copy.copy(a)
for i in range(h):
    bool = True
    for j in range(w):
        if a[i][j] == '#':
            bool = False
    if bool:
        index -= 1
        del ans[index + i]
ans_1 = copy.copy(ans)
key = 1
for i in range(w):
    bool = True
    for j in range(h - (1 - index)):
        if ans[j][i] == '#':
            bool = False
    if bool:
        key -= 1
        for k in range(h - (1 - index)):
            ans_1[k] = ans_1[k][:(i + key)] + ans_1[k][(i + key + 1):]
for i in range(len(ans_1)):
    print(ans_1[i])

H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]
# 列について
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            break
    # すべて空白だったらx印
    else:
        for l in range(W):
            A[i][l] = "x"

# 行について
for i in range(W):
    for j in range(H):
        if A[j][i] == "#":
            break
    else:
        for l in range(H):
            A[l][i] = "x"
for i in range(H):
    x_cnt = 0
    for j in range(W):
        if A[i][j] != "x":
            print(A[i][j], end="")
        else:
            x_cnt += 1

    if x_cnt < W:
        print()
    else:
        pass


h, w = map(int, input().split())
aa = [list(input()) for i in range(h)]
bb = list(zip(*aa))

cc =  [b for b in bb if any(x == '#' for x in b)]
dd =list(zip(*cc))
ee = [d for d in dd if any(x == '#' for x in d)]


for i in range(len(ee)):
    print(''.join(ee[i]))

import itertools
H, W = map(int, input().split())
A = []
for _ in range(H):
    a = list(input())
    if a.count("#") != 0:
        A.append(a)

H = len(A)
if H == 1:
    A = list(itertools.chain.from_iterable(A))
    cnt = []
    for ans in A:
        if ans == "#":
            cnt.append(ans)
    print("".join(cnt))
else:
    L = []
    for w in range(W):
        l = []
        for h in range(H):
            if A[h][w] == "#":
                l = []
                break
            l.append(w)
        if len(l) != 0:
            L.append(l[0])

    dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]
    for ans in A:
        ans = dellist(ans, L)
        print("".join(ans))

import numpy as np
H, W = map(int, input().split())
x = [list(map(str, list(input()))) for l in range(H)]

y = []
for i in range(H):
    if set(x[i]) != {"."}:
        y.append(x[i])

z = np.array(y)
zz = np.rot90(z)
zzz = zz.tolist()

ans = []
for i in range(W):
    if set(zzz[i]) != {"."}:
        ans.append(zzz[i])

a = np.array(ans)
b = np.rot90(a, -1)
c = b.tolist()

for i in range(len(c)):
    print(*c[i], sep='')

import numpy as np

h, w = list(map(int, input().split()))
a = np.array([list(input()) for _ in range(h)])

for i in range(h):
    if np.count_nonzero(a[i] == '#') == 0:
        a[i] = 'x'
for i in range(w):
    if np.count_nonzero(a[:, i] == '#') == 0:
        a[:, i] = 'x'

for i in range(h):
    if res := ''.join([x for x in a[i] if x != 'x']):
        print(res)


ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
import sys
h,w = ma()
t="."*w
ls=[]
for i in range(h):
    s=input()
    if s!=t:
        ls.append(s)

l = len(ls)
t="."*l
ans = [[] for i in range(l)]
for i in range(w):
    f=False
    for j in range(l):
        if ls[j][i]=="#":
            f=True
    if f:
        for j in range(l):
            ans[j].append(ls[j][i])
for a in ans:
    print("".join(a))


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

L, side, ver = [], [], []

for i in range(H):
    a = list(input())
    L.append(a)

def check(n, inlist, outlist):
    """[summary]
    全て白マスの行を削除する
    転置行列を返すので列の判定にも対応可能
    Args:
        n ([type]): 配列サイズ
        inlist ([type]): 入力する二次元配列
        outlist ([type]): 出力する二次元配列

    Returns:
        [list]: 不要な要素を削除して転置して返す
    """    
    for i in range(n):
        if ('#' in inlist[i]) == True:
            outlist.append(inlist[i])
    return list(map(list, zip(*outlist)))

side = check(H, L, side)
ver = check(len(side), side, ver)

for i in range(len(ver)):
    print(''.join(ver[i]))

H,W = map(int,input().split())
ans = []
for i in range(H):
    a = input()
    if a != "."*W:
        ans.append(a)
H = len(ans)
ans2 = list(map(list,zip(*ans)))
while ["."]*H in ans2:
    ans2.remove(["."]*H)
trueans = list(map(list,zip(*ans2)))
for i in trueans:
    print("".join(i))

H, W = list(map(int, input().split()))
a_list = [list(input()) for _ in range(H)]
dot_cnt = [sum([a == '.' for a in a_col]) for a_col in a_list]
exist_idx = [i for i, num in enumerate(dot_cnt) if num != W]
st = set(range(W))
for i in exist_idx:
    dot_idx = [i for i, a in enumerate(a_list[i]) if a == '.']
    st = st & set(dot_idx)
for i in exist_idx:
    print((''.join([a for i, a in enumerate(a_list[i]) if i not in st])))


H, W = map(int, input().split())
grid = [input() for _ in range(H)]

cnt_y = [0]*H
cnt_x = [0]*W

for i in range(H):
    for j in range(W):
        if grid[i][j] == '.': cnt_y[i] += 1

for j in range(W):
    for i in range(H):
        if grid[i][j] == '.': cnt_x[j] += 1

for i in range(H):
    res = ''
    for j in range(W):
        if cnt_y[i] < W and cnt_x[j] < H:
            res += grid[i][j]
    if len(res) > 0: print(res)

from typing import List


def answer(h: int, w: int, a: List[str]) -> List[str]:
    for i in range(2):
        white_line = '.' * w
        loop = a.count(white_line)
        for _ in range(loop):
            a.remove(white_line)
        a = [''.join(line) for line in (list(zip(*a)))]
        if i == 0:
            w = h - loop

    return a


def main():
    h, w = list(map(int, input().split()))
    a = [input() for _ in range(h)]
    for i in answer(h, w, a):
        print(i)


def __starting_point():
    main()

__starting_point()

h, w = list(map(int, input().split()))
A = [input() for _ in range(h)]
B = list()
ng = "." * w
cnt = 0
for i, a in enumerate(A):
    if a == ng:
        cnt += 1
    else:
        B.append(a)
A = list(["".join(x) for x in zip(*B)])
ng = "." * (h - cnt)
B = list()


for i, a in enumerate(A):
    if a == ng:
        cnt += 1
    else:
        B.append(a)

for a in zip(*B[::-1]):
    print(("".join(a[::-1])))


H, W = map(int,input().split())
A = [input() for i in range(H)]
i = 0
for a in range(H):
    if '#' not in A[i]:
        del A[i]
        H -= 1
        i -= 1
    i += 1
#ここまでで行消去
i = 0
for a in range(W):
    f = True
    for j in range(H):
        if A[j][i] == '#':
            f = False
            break
    if f:
        for j in range(H):
            A[j] = A[j][:i] + A[j][i+1:]
        W -= 1
        i -= 1
    i += 1
for a in A:
    print(a)

h,w = map(int,input().split())
s = 0
li = []
lire = []
linew = []
for i in range(h):
    li.append(input())
for i in range(w):
    for j in range(h):
        if li[j][i] == ".":
            s = 1
        else:
            s = 0
            break
    if s == 1:
        lire.append(i)
        s = 0
for i in range(h):
    a = ""
    for j in range(w):
        if j not in lire:
            a += li[i][j]
    linew.append(a)
for i in range(len(linew)):
    if "#" not in linew[i]:
        continue
    else:
        print(linew[i])

h,w=map(int,input().split())
table=[]
for i in range(h):
    table.append(list(input()))
count=0
while True:
    if not '#' in table[count]:
        table.pop(count)
        h-=1
        count=0
        continue
    if count==h-1:
        break
    count+=1
count=0
if h==1:
    table=[n for n in table[0] if n!='.']
else:
    while True:
        tmp=[]
        for i in range(h):
            tmp.append(table[i][count])
        if not '#' in tmp:
            for j in range(h):
                table[j].pop(count)
            w-=1
            count=0
            continue
        if count==w-1:
            break
        count+=1
for row in table:
    print(''.join(row))

h, w = list(map(int, input().split()))
a = []
for i in range(h):
    line = input()
    if line != "." * w:
        a.append(list(line))

h = len(a)

w_pass =[]
for i in range(w):
    for j in range(h):
        if a[j][i] != ".":
            break
    else:
        w_pass.append(i)

for i in range(h):
    line = ""
    for j in range(w):
        if j in w_pass:
            pass
        else:
            line += a[i][j]
    print(line)


h, w = list(map(int, input().split()))
a = []
for i in range(h):
  s = input()
  if s.count('#') > 0:
    a.append(s)

b = [0 for i in range(w)]
for gl in a:
  for i in range(w):
    if gl[i] == '#':
      b[i] += 1
for gl in a:
  v = ''
  for i in range(w):
    if b[i] > 0:
      v += gl[i]
  print (v)



h,w = map(int,input().split())
a = []
hh = 0
for _ in range(h):
  x = [xx for xx in input()]
  if x.count("#") > 0:
    a.append(x)
    hh += 1
b = []

count = 0
if hh > 1:
  wlist = []
  for i in range(w):
    for j in range(hh):
      b.append(a[j][i])
    if b.count("#") == 0:
      wlist.append(i)
    b = []
  for k in wlist:
    for l in range(hh):
      a[l].pop(k-count)
    count += 1
  for m in range(len(a)):
    print("".join(a[m]))
else:
  a = list(*a)
  ans = [aa for aa in a if aa == "#"]
  print("".join(ans))

H, W = list(map(int, input().split()))
a = [list(input()) for i in range(H)]
a = [x for x in a if '#' in x]
aT = list(zip(*a))
aT = [x for x in aT if '#' in x]
a = list(zip(*aT))
for i in a:
    print((''.join(i)))


h,w = list(map(int,input().split()))
masu = []
for i in range(h):
    tmp = str(input())
    masu.append(tmp)

tmp_h = [int(0) for i in range(h)]
tmp_w = [int(0) for j in range(w)]
for i in range(h):
    for j in range(w):
        if masu[i][j]=='.':
            tmp_h[i] += 1
            tmp_w[j] += 1
#print(tmp_h)
#print(tmp_w)

ans = []
for i in range(len(tmp_h)):
    if tmp_h[i] != w:
        tmp = ''
        for j in range(w):
            if tmp_w[j] != h:
                tmp += masu[i][j]
        ans.append(tmp)

#for i in range(h):
#    print(masu[i])
#print('-----')
for i in range(len(ans)):
    print((ans[i]))


import numpy as np
h,w=map(int, input().split())
a=[list(input()) for i in range(h)]
a=np.array(a)

a2=[]
a3=[]
for i in range(h):
  if "#" in a[i]:
    a2.append(a[i])
a2=np.array(a2)
a2=a2.T

for i in range(len(a2)):
  if "#" in a2[i]:
    a3.append(a2[i])
a3=np.array(a3)
a3=a3.T
for i in range(len(a3)):
  print("".join(a3[i]))

import numpy as np

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

maze = []
for i in range(h):
    row = list(input())
    if "#" in row:
        maze.append(row)
        
maze = np.array(maze)
maze = np.rot90(maze)

ans = []
for row in maze:
    if "#" in row:
        ans.append(row)
        
ans = np.rot90(ans, -1)

for r in ans:
    print("".join(r))

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

a=[list(map(str,input().split())) for i in range(H)]
for i in range(H):
    a[i]=list(a[i][0])
flag=True
for i in range(H):
    for j in range(W):
        if a[H-1-i][j]!='.':
            flag=False
            break
    if flag:
        del(a[H-1-i])
    flag=True
for i in range(W):
    for j in range(len(a)):
        if a[j][W-1-i]!='.':
            flag=False
            break
    if flag:
        for j in range(len(a)):
            del(a[j][W-1-i])
    flag=True

for aaa in a:
    print("".join(aaa))

h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
x = list()
y = list()
for i in range(h):
    if "#" in a[i]:
        x.append(i)
for j in range(w):
    cnt = 0
    for k in range(h):
        if a[k][j] == "#":
            y.append(j)
            break
for p in x:
    z = ""
    for q in y:
        z += a[p][q]
    print(z)

h, w = map(int,input().split())
a_l = [ list(input()) for _ in range(h) ]
sub_array = []
for i in range(h):
    if '#' in a_l[i]:
        sub_array.append(a_l[i])

sub_array = [list(x) for x in zip(*sub_array)]
ans = []
for j in range(w):
    if '#' in sub_array[j]:
        ans.append(sub_array[j])
_ = [print(''.join(list(x))) for x in zip(*ans)]

N,M = map(int,input().split())
ls = []
for i in range(N):
    ls.append(list(input()))
yoko = []
tate = [i for i in range(M)]
for i in range(N):
    if ls[i].count('.') == M:
        yoko.append(i)
for i in range(N):
    for j in range(M):
        if ls[i][j] == '#' and j in tate:
            tate.remove(j)
tate2 = list(range(M))
for i in range(M):
    if i in tate:
        tate2.remove(i)

ansls = []
for i in range(N):
    if not i in yoko:
        ansls.append([ls[i][j] for j in tate2])
for i in ansls:
    print(''.join(i))

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

for i in range(h):
    line = list(input())
    if line != ["."] * w:
        masu.append(line)

h = len(masu)
del_i = []
for i in range(w):
    for j in range(h):
        if masu[j][i] != ".":
            break
    else:
        del_i.append(i)
w = len(del_i)
for j in range(w):
    for i in range(h):
        masu[i].pop(del_i[j] - j)

for i in range(h):
    print(("".join(masu[i])))


import numpy as np

H,W = map(int,input().split())
hw = np.array([list(input()) for _ in range(H)])

gyo = np.all(hw == ".",axis=1)
retu= np.all(hw == ".",axis=0)

for i in range(H):
    if not gyo[i]==True:
        for j in range(W):
            if not retu[j]==True:
                print(hw[i][j],end="")
        print()

H, W = list(map(int, input().split()))
a = [list(input()) for i in range(H)]
a = [x for x in a if '#' in x]
aT = list(zip(*a))
aT = [x for x in aT if '#' in x]
a = list(zip(*aT))
for i in a:
    print((''.join(i)))


H,W = map(int,input().split())
A = [""] * H
for i in range(H):
  A[i] = input()
  
row = [False] * H
col = [False] * W

for j in range(H):
  for k in range(W):
    if A[j][k] == "#":
      row[j] = True
      col[k] = True
      
for l in range(H):
  if row[l]:
    for m in range(W):
      if col[m]:
        print(A[l][m], end = "")
    print()

h,w = map(int,input().split())
a = [input() for _ in range(h)]

hl=[]
wl=[]

for i in range(h):
    if a[i]=="."*w:
        hl +=[i]
for i in range(w):
    if all([a[j][i]=="." for j in range(h)]):
        wl += [i]


for i in range(h):
    if i not in hl:
        for j in range(w):
            if j not in wl:
                print(a[i][j],end="")
        else:
            print("")

import numpy as np

def main():

    H,W = list(map(int,input().split()))
    A = [[0 if s == "." else 1 for s in list(input())] for _ in range(H)]

    for i in reversed(list(range(H))):
        if sum(A[i]) == 0:
            A.pop(i)

    A = np.array(A).T.tolist()
    for i in reversed(list(range(W))):
        if sum(A[i]) == 0:
            A.pop(i)
    A = np.array(A).T.tolist()

    for i in range(len(A)):
        print(("".join(["." if i == 0 else "#" for i in A[i]])))

main()


h, w = list(map(int, input().split()))
grid = [input() for _ in range(h)]

def check_row(grid):
    for i in range(len(grid)):
        if "#" not in grid[i]:
            return i
    return -1

def check_col(grid):
    grid_inv = []
    for i in range(len(grid[0])):
        grid_inv.append("".join(row[i] for row in grid))
    return check_row(grid_inv)

while True:
    if check_row(grid) != -1:
        del grid[check_row(grid)]
        continue
    elif check_col(grid) != -1:
        d = check_col(grid)
        for i in range(len(grid)):
            grid[i] = grid[i][:d] + grid[i][d+1:]
    else:
        break

for g in grid:
    print(g)


h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
x = list()
y = list()
for i in range(h):
    if "#" in a[i]:
        x.append(i)
for j in range(w):
    cnt = 0
    for k in range(h):
        if a[k][j] == "#":
            y.append(j)
            break
for p in x:
    z = ""
    for q in y:
        z += a[p][q]
    print(z)

h,w = map(int, input().split())
a = [str(input()) for _ in range(h)]
b = []
for i in range(h):
    if a[i] != '.'*w:
        b.append(a[i])
c = []
for h in range(w):
    num = 0
    for j in b:
        if j[h] == '.':
            num += 1
    if num == len(b):
        c.append(h)
for k in b:
    word = ""
    for l in range(w):
        if l not in c:
            word += k[l]
    print(word)

H,W = map(int,input().split())
grid = [input().split() for _ in range(H)]
check = []

for i in range(H):
    if '#' not in grid[i][0]:
        check.append(i-len(check))
for i in check:
    grid = grid[:i] + grid[i+1:]
check = []

for i in range(W):
    if all(grid[j][0][i]=='.' for j in range(len(grid))):
        check.append(i - len(check))
for i in check:
    for k in range(len(grid)):
        grid[k][0] = grid[k][0][:i] + grid[k][0][i+1:]
        
for i in grid:
    print(i[0])

import numpy as np
h,w=map(int,input().split())
s=np.array([list(input()) for i in range(h)])
s=(s[np.any(s=='#',axis=1)])
s=(s[:,np.any(s=='#',axis=0)])
for i in s:
    print("".join(map(str,i)))

H, W = list(map(int, input().split()))
A = []
for _ in range(H):
    a = input()
    if "#" in a:
        A.append(a)
A_ = ["" for _ in range(len(A))]
for x in range(W):
    f = False
    for a in A:
        if a[x] == "#":
            f = True
            break
    if f:
        for y, a in enumerate(A):
            A_[y] += a[x]
for a in A_:
    print(a)


h,w=map(int, input().split())
a=[i for i in [input() for _ in range(h)] if '#' in i]
b=[i for i in zip(*a) if '#' in i]
for i in zip(*b):
  print(''.join(i))

H, W = map(int, input().split())
row = [False] * H
col = [False] * W
grid = []
for i in range(H):
    grid.append(input())

for i in range(H):
    for j in range(W):
        if grid[i][j] == '#':
            row[i] = True
            col[j] = True

for i in range(H):
    if not row[i]: continue
    for j in range(W):
        if not col[j]: continue
        print(grid[i][j], end='')
    print()

H, W = map(int, input().split())
a = [list(input()) for _ in range(H)]
resH = [True] * H
resW = [True] * W

for h in range(H):
    judge = False
    for w in range(W):
        if a[h][w] == "#":
            judge = True
    resH[h] = judge

for w in range(W):
    judge = False
    for h in range(H):
        if a[h][w] == "#":
            judge = True
    resW[w] = judge

for h, row in enumerate(a):
    tmp = []
    for w, element in enumerate(row):
        if resH[h] and resW[w]:
            tmp.append(element)
    if tmp:
        print(*tmp, sep="")


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

h_set = set()
w_set = set()
B = [input() for i in range(H)]
for i in range(H):
  for j in range(W):
    if B[i][j] == '#':
      w_set.add(j)
      h_set.add(i)
      
for i in range(H):
  if i in h_set:
    t = ""
    for j in range(W):
      if j in w_set:
        t += B[i][j]
    print(t)

h, w = list(map(int, input().split()))
fields = [list(input()) for _ in range(h)]
ans = [[0] * w] * h
for i in range(h):
    if "#" not in fields[i]:
        ans[i] = [1] * w
for i in range(w):
    count = 0
    for j in range(h):
        if fields[j][i] == ".":
            count += 1
    if count == h:
        for j in range(h):
            ans[j][i] = 1
tmp = []
for out, flag in zip(fields, ans):
    content = []
    for i in range(w):
        if flag[i] == 0:
            content.append(out[i])
    tmp.append(content)
for content in tmp:
    if content != []:
        print(("".join(content)))


H, W = list(map(int, input().split()))
A = [[p for p in input()] for _ in range(H)]

y = 0
while(y < len(A)):
    if all([p == '.' for p in A[y]]):
        del A[y]
    else:
        y += 1

x = 0
while(x < len(A[0])):
    if all([row[x] == '.' for row in A]):
        for row in A:
            del row[x]
    else:
        x += 1

for row in A:
    print((''.join(row)))


lst = input().split()
H = int(lst[0])
W = int(lst[1])

def update(S, n):
   return S[:n] + '*' + S[n + 1:]

field = []

for i in range(H):
   a = input()
   if a != '.' * W:
      field.append(a)

for i in range(W):
   t = 0
   for j in range(len(field)):
      if field[j][i] != '.':
         t = 1
         break
   if t == 0:
      for j in range(len(field)):
         field[j] = update(field[j], i)

for s in field:
   print(s.replace('*', ''))

H,W=map(int,input().split())
a=[list(input()) for _ in range(H)]
b=[]
for i in range(H):
    if '#' in a[i]:
        b.append(a[i])
c=[[] for _ in range(len(b))]
for j in range(W):
    flag=False
    for i in range(len(b)):
        if b[i][j]=='#':
            flag=True
    if flag:
        for i in range(len(b)):
            c[i].append(b[i][j])
for i in range(len(c)):
    for j in range(len(c[i])):
        print(c[i][j],end='')
    print()


h, w = map(int, input().split())
a = [input() for i in range(h)]
vdel = []
sdel = []

for i in range(h):
    if a[i].count('.') == w:
        sdel.append(i)

for i in range(w):
    cnt = 0
    for j in range(h):
        if a[j][i] == '.':
            cnt += 1
    if cnt == h:
        vdel.append(i)
i = 0
lens = len(sdel)-1
h -= lens+1
while i <= lens:
    del a[sdel[lens]]
    lens -= 1

for i in range(h):
    tmp = ''
    for j in range(w):
        if j not in vdel:
            tmp += a[i][j]
    print(tmp)

H,W = map(int,input().split())
a = [list(input()) for _ in range(H)]

#行
r = [0]*H  #行ごとの#の数
for i in range(H):
    r[i]=a[i].count('#')
#列
c = [0]*W  #列ごとの#の数
for i in a:
    for j in range(W):
        if i[j]=='#':
            c[j]+=1
            
for i in range(H):
    a[i] = [a[i][j] for j in range(W) if c[j]!=0]


for i in range(H):
    if r[i]!=0:
        print(''.join(a[i]))

# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


H, W = zz()
board = []
for h in range(H):
    board.append(list(input()))
board = np.array(board)
ans1 = []
for h in range(H):
    if ('#' in board[h]):
        ans1.append(board[h])
ans2 = []
board = np.array(ans1)
for w in range(W):
    if ('#' in board[:, w]):
        ans2.append(board[:, w])
ans2 = np.array(ans2).T

for line in ans2:
    print(*line, sep='')


h,w=map(int,input().split())
A=[]
ans=[]
for i in range(h):
    A.append(list(input()))
for a in A:
    if a != ['.']*w:
        ans.append(a)
counter=[]
for i in range(w):
    flag=0
    for j in range(len(ans)):
        if ans[j][i]=='#':
            flag=1
            break
    if flag==1:
        counter.append(i)
        
for a in ans:
    temp=''
    for i in counter:
        temp+=a[i]
    print(temp)

H,W=list(map(int,input().split()))
delh=[]
delw=[]

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

for j in range(H):
    temp=0
    for k in range(W):
        if sq[j][k]==".":
            temp+=1
    if temp==W:
        delh.append(j)

for l in range(W):
    temp=0
    for m in range(H):
        if sq[m][l]==".":
            temp+=1
    if temp==H:
        delw.append(l)

for n in range(len(delh)):
    del sq[delh[n]]
    for q in range(len(delh)):
        delh[q]-=1
H-=len(delh)

for o in range(len(delw)):
    for p in range(H):
        del sq[p][delw[o]]
    for r in range(len(delw)):
        delw[r]-=1
        
for s in range(H):
    print(("".join(sq[s])))


import numpy as np

H,W = map(int,input().split())
hw = np.array([list(input()) for _ in range(H)])

gyo = np.all(hw == ".",axis=1)
retu= np.all(hw == ".",axis=0)

for i in range(H):
	if not gyo[i]==True:
		for j in range(W):
			if not retu[j]==True:
				print(hw[i][j],end="")
		print()

h,w=map(int,input().split())
lis=[list(input()) for i in range(h)]

fin=[]
num=[0]*w

for l in lis:
  if l.count(".") != w:
    fin.append(l)
  for i in range(w):
    if l[i]==".":
      num[i]+=1

for f in fin:
  ans=[]
  for i in range(len(num)):
    if num[i]!=h:
      ans.append(f[i])
  print(*ans,sep='')
    

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

grid = []
for _ in range(h):
    x = input()
    if x.count(".") != len(x):
        grid.append(x)

grid = list(map(list, zip(*grid)))

grid_t = []
for g in grid:
    if g.count(".") != len(g):
        grid_t.append(g)

ans = list(map(list, zip(*grid_t)))

for a in ans:
    print("".join(a))

h, w = map(int, input().split())
a = [''] * h
for i in range(h):
	a[i] = input()
 
row = [False] * h
col = [False] * w
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True
 
for i in range(h):
	if row[i]:
		for j in range(w):
			if col[j]:
				print(a[i][j], end = '')
		print()

H,W = map(int,input().split())
a = [input() for i in range(H)]
b = [0] * W
c = [0] * H
for i in range(H):
    cnt = 0
    for j in range(W):
        if a[i][j] == '#':
            b[j] += 1
            cnt += 1
    c[i] = cnt 

for i in range(H):
    if c[i]==0:
        continue
    for j in range(W):
        if b[j]!=0:
            print(a[i][j],end='')
    print()


H,W = map(int,input().split())
A = [input() for i in range(H)]

B = []
for row in A:
    if all(a=='.' for a in row): continue
    B.append(row)

C = ['' for _ in range(len(B))]
for col in zip(*B):
    if all(a=='.' for a in col): continue
    for i,a in enumerate(col):
        C[i] += a
for row in C:
    print(row)

import math

h, w = map(int, input().split(" "))
aL = [list(input()) for _ in range(h)]

for i in reversed(range(h)):
    if len(set(aL[i])) == 1 and aL[i][0][0] == ".":
        del aL[i]

for i in reversed(range(w)):
    for j in range(len(aL)):
        if aL[j][i] == "#":
            break
    else:
        for k in range(len(aL)):
            del aL[k][i]

for a in aL:
    print("".join(a))

a = input().split()
H = int(a[0])
W = int(a[1])
adj = int(0)
s = []
p = []

for k in range(H):
    m = input()
    for i in range(W):
        p.append(m[i])
    s.append(p)
    p = []

for i in range(W):
    i = i - adj
    temp = int(0)
    for k in range(H):
        if s[k][i] == "#":
            temp = 1
            break
        else:
            pass
    if temp == 0:
        for k in range(H):
            del s[k][i]
        adj += 1
    else:
        pass

W = W - adj
adj = 0

for i in range(H):
    i = i - adj
    temp = int(0)
    for k in range(W):
        if s[i][k] == "#":
            temp = 1
            break
        else:
            pass
    if temp == 0:
        del s[i]
        adj += 1
    else:
        pass

H = H - adj

for i in range(H):
    tinpo = ''.join(s[i])
    print(tinpo)

#!/usr/bin/env python3
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    H, W = list(map(int, input().split()))
    a = []
    white = '.' * W
    for i in range(H):
        s = input()
        if s == white:
            pass
        else:
            a.append(s)

    black = []
    for w in range(W):
        for h in range(len(a)):
            if a[h][w] == '#':
                black.append(w)

    black = sorted(list(set(black)))
    for h in range(len(a)):
        t = ''
        for b in black:
            t += a[h][b]
        print(t)

def __starting_point():
    main()

__starting_point()

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

L, side, ver = [], [], []

for i in range(H):
    a = list(input())
    L.append(a)

for i in range(H):
    if ('#' in L[i]) == True:
        side.append(L[i])

side = list(map(list, zip(*side)))

for i in range(len(side)):
    if ('#' in side[i]) == True:
        ver.append(side[i])

ver = list(map(list, zip(*ver)))

for i in range(len(ver)):
    print(''.join(ver[i]))

h,w = map(int,input().split())
a = [list(input()) for i in range(h)]
delrow = []
delline = []
for i in range(w):
  whiteline = 0
  for j in range(h):
    if a[j][i] == ".":
      whiteline += 1
    if whiteline == h:
      delline.append(i)
for i in range(h):
  whiterow = 0
  for j in range(w):
    if a[i][j] == ".":
      whiterow += 1
    if whiterow == w:
      delrow.append(i)
for i in range(h):
  if i in delrow:
    continue
  else:
    ans = ""
    for j in range(w):
      if j in delline:
        continue
      else:
        ans += a[i][j]
  print(ans)

h, w = map(int, input().split())
a = [''] * h
for i in range(h):
	a[i] = input()

row = [False] * h
col = [False] * w
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True

for i in range(h):
	if row[i]:
		for j in range(w):
			if col[j]:
				print(a[i][j], end = '')
		print()


h,w=map(int,input().split())
A=[]
ans=[]
for i in range(h):
  A.append(list(input()))
for a in A:
  if a != ['.']*w:
    ans.append(a)
counter=[]
for i in range(w):
  flag=0
  for j in range(len(ans)):
    if ans[j][i]=='#':
      flag=1
      break
  if flag==1:
    counter.append(i)

for a in ans:
  tmp=''
  for i in counter:
    tmp=tmp+a[i]
  print(tmp)

h,w=map(int,input().split())
a=[]
data=[0]*w
for i in range(h):
  a_=input()
  if a_!='.'*w:
    a.append(a_)
    for j in range(w):
      if a_[j]=='.':
        data[j]+=1
n=len(a)
for i in range(n):
  ans=[]
  for j in range(w):
    if data[j]!=n:
      ans.append(a[i][j])
  print(*ans,sep='')

H, W = map(int,input().split())
A = [input() for i in range(H)]
row = [False]*H
col = [False]*W
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            row[i] = True
            col[j] = True
for i in range(H):
    if row[i]:
        for j in range(W):
            if col[j]:
                print(A[i][j], end = '')
        print()

# 適当に愚直
h, w = list(map(int, input().split()))
table = [list(input()) for _ in range(h)]
table2 = []
for t in table:
    if t != ["."] * w:
        table2.append(t)
table2 = list(zip(*table2))
table3 = []
for t in table2:
    if list(t) != ["."] * len(t):
        table3.append(t)
table3 = list(zip(*table3))
for t in table3:
    print(("".join(t)))


h, w = map(int, input().split())
grid = []
for _ in range(h):
  grid.append(list(input()))
  
delete_row = []
for i in range(h):
  for j in range(w):
    if grid[i][j] != '.':
      break
    elif j == w-1:
      delete_row.append(i)
      
delete_col = []
for j in range(w):
  for i in range(h):
    if grid[i][j] != '.':
      break
    elif i == h-1:
      delete_col.append(j)
      
for i in range(h):
  if i not in delete_row:
    for j in range(w):
      if j not in delete_col:
        print(grid[i][j], end='')
    print()


import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return list(map(int, input().split()))
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    h,w = i_map()
    l = []
    for i in range(h):
        a = input()
        if "#" in a:
            l.append(a)
    l = [list(i) for i in zip(*l)]
    ans = []

    for i in l:
        if "#" in i:
            ans.append(i)

    ans = [i for i in zip(*ans)]
    for i in ans:
        print(("".join(i)))





def __starting_point():
    main()

__starting_point()

import sys

input = sys.stdin.readline
H, W = map(int, input().split())
grid = []
for _ in range(H):
    grid.append(list(input().strip()))

h_set = set()
for i in range(H):
    flag = True
    for j in range(W):
        if grid[i][j] == "#":
            flag = False
            break
    if flag:
        h_set.add(i)

w_set = set()
for j in range(W):
    flag = True
    for i in range(H):
        if grid[i][j] == "#":
            flag = False
            break
    if flag:
        w_set.add(j)

for i in range(H):
    if i in h_set:
        continue
    for j in range(W):
        if j in w_set:
            continue
        print(grid[i][j], end="")
    print("")

H, W = [int(x) for x in input().split()]
A = [input().strip() for _ in range(H)]

B = []
for i in range(H):
    if "#" in A[i]:
        B.append(A[i])

ans = []
for j in range(W):
    for i in range(len(B)):
        if "#" ==  B[i][j]:
            ans.append(j)
            break

for i in range(len(B)):
    for j in ans:
        print(B[i][j], end="")
    print()






h, w = map(int, input().split())
a = [''] * h
for i in range(h):
	a[i] = input()

row = [False] * h
col = [False] * w
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True

for i in range(h):
	if row[i]:
		for j in range(w):
			if col[j]:
				print(a[i][j], end = '')
		print()


#12 B - Grid Compression
H,W = map(int,input().split())
a = [list(input()) for _ in range(H)]

i = 0
while i < len(a):
    if all(m == '.' for m in a[i]) :
        a.pop(i)
    else:
        i += 1
#加工したaにおけるHを保持しなおす
H_sc = len(a)
w = 0
while w < len(a[0]):
    cnt = 0
    for h in range(H_sc):
        if a[h][w] == '#':
            w += 1
            break
        else:
            cnt += 1
    if cnt == H_sc:
        for b in a:
            b.pop(w)
for g in a:
    print(''.join(g))

def main():
    h, w = list(map(int, input().split()))
    board = []
    safe_h = set()
    safe_w = set()
    for i in range(h):
        board.append(list(input()))
    for i in range(h):
        for j in range(w):
            if board[i][j] == '#':
                safe_h.add(i)
                safe_w.add(j)
    for i in safe_h:
        for j in safe_w:
            print(board[i][j], end='')
        print()


def __starting_point():
    main()
__starting_point()

h, w = (int(i) for i in input().split())
list_a = [input() for s in range(0, h)]
list_tmp = []
for i in range(0, h):
    for j in range(0, w):
        if list_a[i][j] == '#':
            list_tmp.append(list(list_a[i]))
            break
# 転置... https://note.nkmk.me/python-list-transpose/　参照
list_tmp_t = [list(x) for x in zip(*list_tmp)]
list_tmp2 = []
for i in range(0, len(list_tmp_t)):
    for j in range(0, len(list_tmp_t[i])):
        if list_tmp_t[i][j] == '#':
            list_tmp2.append(list(list_tmp_t[i]))
            break
# 転置... https://note.nkmk.me/python-list-transpose/　参照
list_ans = [list(x) for x in zip(*list_tmp2)]
for i in range(0, len(list_ans)):
    print("".join(list_ans[i]))

# ABC107
# B Grid Compression 答え見た
H, W = map(int, input().split())
a = [""] * H
a
for i in range(H):
    a[i] = input()


row = [False] * H
col = [False] * W
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            row[i] = True
            col[j] = True
for i in range(H):
    if row[i]:
        for j in range(W):
            if col[j]:
                print(a[i][j],end="")
        print()
pass


h, w = map(int, input().split())
A = [input() for i in range(h)]
row = [False] * h
col = [False] * w
for i in range(h):
    for j in range(w):
        if A[i][j] == '#':
            row[i] = True
            col[j] = True
for i in range(h):
    if row[i]:
        for j in range(w):
            if col[j]:
                print(A[i][j], end = '')
        print()

h,w=map(int, input().split())
alist=['']*h
for i in range(h):
  alist[i]=input()
hlist=[]
wlist=[]
for i in range(h):
  flag=False
  for j in range(w):
    if alist[i][j]=='#':
      flag=True
  if flag:
    hlist.append(i)
for i in range(w):
  flag=False
  for j in range(h):
    if alist[j][i]=='#':
      flag=True
  if flag:
    wlist.append(i)
for i in hlist:
  ans=[]
  for j in wlist:
    ans.append(alist[i][j])
  print(''.join(ans))

h,w = map(int, input().split())
a0 = [[] for i in range(h)]
for i in range(h):
  a0[i] = input()
a = [j for j in a0 if "#" in j]
at0 = list(map(list, zip(*a)))
for k in range(len(at0)):
  at0[k] = "".join(at0[k])
at = [l for l in at0 if "#" in l]
for m in list(map(list, zip(*at))):
  print("".join(m))

h, w = map(int, input().split())
a = [''] * h
for i in range(h):
	a[i] = input()

row = [False] * h
col = [False] * w
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True

for i in range(h):
	if row[i]:
		for j in range(w):
			if col[j]:
				print(a[i][j], end = '')
		print()


H,W=map(int,input().split())
G=[list(input()) for i in range(H)]
allwhite=['.']*W
tmp=[]
for i in range(H):
    if G[i]!=allwhite:
        tmp.append(G[i])
G=tmp
ans=["" for i in range(len(G))]
for j in range(W):
    p=False
    for i in range(len(G)):
        if G[i][j]=='#':
            p=True
            break
    if p:
        for i in range(len(G)):
            ans[i]+=G[i][j]
print(*ans,sep='\n')