AtCoder Beginner Contest 107 - Grid Compression

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: EASY

Starter code:

Solutions:
(h, w) = map(int, input().split())
a = [[j for j in input()] for i in range(h)]
b = [x for x in a if '#' in x]
c = zip(*[y for y in zip(*b) if '#' in y])
for d in c:
	print(''.join(d))


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)


(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()


def f(l, x):
	z = []
	for i in range(x):
		if set(l[i]) != set('.'):
			z.append(l[i])
	return list(map(list, zip(*z)))
(h, w) = map(int, input().split())
a = [list(input()) for _ in range(h)]
l = f(f(a, h), w)
for i in range(len(l)):
	print(''.join(l[i]))


(H, W) = map(int, input().split())
A = [input() for _ in range(H)]
A = list(filter(lambda a: any((x == '#' for x in a)), A))
A = list(filter(lambda a: any((x == '#' for x in a)), zip(*A)))
for a in zip(*A):
	print(''.join(a))


(H, W) = [int(_) for _ in input().split()]
A = [input() for i in range(H)]
A = [''.join(row) for row in zip(*A) if row.count('#') > 0]
A = [''.join(row) for row in zip(*A) if row.count('#') > 0]
print('\n'.join(A))


(H, W) = map(int, input().split())
A = [[i for i in input()] for _ in range(H)]
B = [x for x in A if '#' in x]
C = zip(*[y for y in zip(*B) if '#' in y])
for d in C:
	print(''.join(d))


(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) = 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())
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())
a = [input() for i in range(h)]
b = [i for i in a if i.count('#') > 0]
for i in range(w - 1, -1, -1):
	if sum([b[j][i] == '#' for j in range(len(b))]) == 0:
		for k in range(len(b)):
			b[k] = b[k][:i] + b[k][i + 1:]
print(*b, sep='\n')


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


(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())
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())
A = [list(input()) for i in range(H)]
A = [a for a in A if '#' in a]
A = [a for a in zip(*A) if '#' in a]
A = zip(*A)
for a in A:
	print(''.join(a))


(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) = map(int, input().split())
a = [list(input()) for _ in range(h)]
(ys, xs) = (set(), set())
for y in range(h):
	for x in range(w):
		if a[y][x] == '#':
			ys.add(y)
			xs.add(x)
for y in sorted(list(ys)):
	for x in sorted(list(xs)):
		print(a[y][x], end='')
	print('')


(h, w, *a) = open(0).read().split()
for _ in range(2):
	a = [list(j) for j in zip(*[i for i in a if '#' in i])]
print(*[''.join(i) for i in a], sep='\n')


(h, w) = map(int, input().split())
s = []
l = set()
for i in range(h):
	a = list(input())
	if set(a) != set('.'):
		s.append(a)
		for j in range(w):
			if a[j] == '#':
				l |= {j}
for i in s:
	p = ''
	for j in sorted(list(l)):
		p += i[j]
	print(p)


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


(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')


f = lambda s: zip(*[t for t in s if '#' in t])
for r in f(f(open(0).readlines())):
	print(*r, sep='')


(h, w) = map(int, input().split())
a = []
b = []
for i in range(h):
	n = input()
	if n.count('.') < w:
		a += [n]
for i in range(w):
	if [I[i] for I in a].count('.') == len(a):
		b += [i]
for i in range(len(a)):
	print(''.join([a[i][I] for I in range(w) if I not in b]))


(h, w) = map(int, input().split())
grid = [list(input()) for _ in range(h)]
for _ in range(2):
	grid = list(filter(lambda x: '#' in x, grid))
	grid = [list(x) for x in zip(*grid)]
for i in range(len(grid)):
	print(''.join(grid[i]))


(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()


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


(h, w) = map(int, input().split())
a = []
for _ in range(h):
	wk = input()
	if '#' in wk:
		a.append(wk)
t = []
for j in zip(*a):
	if '#' in j:
		t.append(j)
for list in zip(*t):
	print(''.join(list))


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


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


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


(h, w) = map(int, input().split())
a = [input() for _ in range(h)]
s = set()
t = set()
for i in range(h):
	if '#' in a[i]:
		s.add(i)
		for j in range(w):
			if a[i][j] == '#':
				t.add(j)
for i in s:
	l = ''
	for j in t:
		l += a[i][j]
	print(l)


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())
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) = 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())
(*l,) = eval('input(),' * h)
row = [any((l[i][j] == '#' for i in range(h))) for j in range(w)]
col = ['#' in l[i] for i in range(h)]
for i in range(h):
	f = 0
	for j in range(w):
		if row[j] & col[i]:
			print(l[i][j], end='')
			f = 1
	if f:
		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('')


(H, W) = map(int, input().split())
print(*map(lambda l: ''.join(l), zip(*[column for column in zip(*[row for row in [input() for _ in range(H)] if '#' in row]) if '#' in column])), sep='\n')


[H, W] = [int(i) for i in input().split()]
l = [input() for i in range(H)]
l1 = [x for x in l if x != '.' * W]
l2 = [''.join(x) for x in zip(*l1)]
l3 = [x for x in l2 if any([y if y != '.' else False for y in x])]
print('\n'.join([''.join(x) for x in zip(*l3)]))


(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())
l = []
for i in range(h):
	x = list(input())
	if '#' in x:
		l.append(x)
for j in range(w):
	if all((l[i][j] == '.' for i in range(len(l)))):
		for i in range(len(l)):
			l[i][j] = ''
for i in range(len(l)):
	print(''.join(l[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('\n')


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')


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()


def resolve():
	(h, w) = map(int, input().split())
	A = [[_ for _ in input()] for _ in range(h)]
	B = [i for i in A if '#' in i]
	C = zip(*[i for i in zip(*B) if '#' in i])
	for i in C:
		print(*i, sep='')
resolve()


f = lambda s: zip(*[t for t in s if '#' in t])
for r in f(f(__import__('sys').stdin)):
	print(*r, sep='')


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


(h, w) = map(int, input().split())
table = []
for i in range(h):
	tmp = input()
	if tmp != '.' * w:
		table.append(tmp)
ans = []
for s in zip(*table):
	if '#' in s:
		ans.append(s)
for a in zip(*ans):
	print(''.join(a))


(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]))


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))


(h, w) = map(int, input().split())
a = [list(input()) for _ in [0] * h]
for j in range(w):
	if not any((a[i][j] == '#' for i in range(h))):
		for i in range(h):
			a[i][j] = ''
for i in a:
	if any((j == '#' for j in i)):
		print(''.join(i))


(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)


(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 = []
for i in range(h):
	A.append(list(input()))
B = []
for a in A:
	if '#' in a:
		B.append(a)
C = []
for b in zip(*B):
	if '#' in b:
		C.append(b)
for c in zip(*C):
	print(''.join(c))


(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())
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]))


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


(h, w) = map(int, input().split())
g = [input() for _ in range(h)]
a = ['' for _ in range(h)]
for y in range(w):
	if any((s[y] == '#' for s in g)):
		for x in range(h):
			a[x] += g[x][y]
for s in a:
	if s.count('#'):
		print(s)


(h, w) = map(int, input().split())
ll = [list(input()) for _ in range(h)]
ll = [s for s in ll if '#' in s]
lr = []
for i in range(w):
	if any((l[i] == '#' for l in ll)):
		lr.append(i)
for l in ll:
	ans = ''
	for i in lr:
		ans += l[i]
	print(ans)


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) = map(int, input().split())
A = [input() for _ in range(H)]
A = [aa for aa in A if any((a == '#' for a in aa))]
A = list(map(list, zip(*A)))
A = [aa for aa in A if any((a == '#' for a in aa))]
A = list(map(list, zip(*A)))
for aa in A:
	print(''.join(aa))


(h, w) = map(int, input().split())
b = [input() for i in range(h)]
a = []
for i in b:
	if i != '.' * w:
		a.insert(0, i)
b = []
for i in range(w):
	s = ''
	for j in a:
		s = j[i] + s
	if s != '.' * len(a):
		b.insert(0, s)
c = []
for i in range(len(a)):
	s = ''
	for j in b:
		s = j[i] + s
	print(s)


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


(h, w) = map(int, input().split())
S = [input() for i in range(h)]
A = []
for s in S:
	if '#' in s:
		A.append(s)
nh = len(A)
B = [''] * nh
for x in range(w):
	if any((a[x] == '#' for a in A)):
		for y in range(nh):
			B[y] += A[y][x]
for b in B:
	print(b)


(H, W) = map(int, input().split())
A = [input() for i in range(H)]
b = [x for x in A if '#' in x]
c = zip(*[y for y in zip(*b) if '#' in y])
for d in c:
	print(''.join(d))


(h, w) = [int(x) for x in input().split()]
a = []
for _ in [0] * h:
	ai = list(input())
	if '#' in ai:
		a.append(ai)
tenchi = []
for wi in zip(*a):
	if '#' in wi:
		tenchi.append(wi)
for ansi in zip(*tenchi):
	print(''.join(ansi))


(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)


(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)


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='')


(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())
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())
L = []
for i in range(h):
	L.append(list(input()))
L = [x for x in L if '#' in x]
L = [x for x in zip(*L)]
L = [x for x in L if '#' in x]
L = [x for x in zip(*L)]
for i in range(len(L)):
	print(*L[i], sep='')


(h, w) = map(int, input().split())
T = [list(input()) for i in range(h)]
while ['.'] * w in T:
	T.remove(['.'] * w)
	h -= 1
T = list((list(i) for i in zip(*T)))
while ['.'] * h in T:
	T.remove(['.'] * h)
T = list((list(i) for i in zip(*T)))
for t in T:
	print(''.join(t))


(H, W) = map(int, input().split())
L = [list(input()) for _ in range(H)]
L1 = list(filter(lambda x: ''.join(x) != '.' * W, L))
L2 = list(filter(lambda x: x.count('.') != len(L1), list(zip(*L1))))
for t in list(zip(*L2)):
	print(''.join(t))


(H, W) = map(int, input().split())
lst = []
for _ in range(H):
	s = input()
	if s.find('#') >= 0:
		lst.append(s)
lst2 = []
for tpl in zip(*lst):
	if '#' in tpl:
		lst2.append(tpl)
for tpl in zip(*lst2):
	print(''.join(tpl))


(h, w) = map(int, input().split())
a = [list(input()) for _ in range(h)]
aa = [row for row in a if '#' in row]
aaa = [row for row in zip(*aa) if '#' in row]
for _ in zip(*aaa):
	print(*_, sep='')


(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='')


(n, m) = map(int, input().split())
L = []
d = set('.')
for i in range(n):
	s = input()
	if set(list(s)) != d:
		L.append(list(s))
l = [list(a) for a in zip(*L) if set(a) != set('.')]
for a in zip(*l):
	print(''.join(a))


(H, W) = map(int, input().split())
A = []
for i in range(H):
	A.append(list(input()))
B = []
for a in A:
	if '#' in a:
		B.append(a)
C = []
for b in zip(*B):
	if '#' in b:
		C.append(b)
for c in zip(*C):
	print(''.join(c))


(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]))


(H, W) = map(int, input().split())
A = [list(input()) for h in range(H)]
A1 = [a for a in A if '#' in a]
A2 = [a for a in zip(*A1) if '#' in a]
A3 = [a for a in zip(*A2)]
for a in A3:
	print(''.join(a))


(H, W) = map(int, input().split())
a = [input() for i in range(H)]
for i in range(2):
	a = filter(lambda x: '#' in x, a)
	a = list(zip(*[list(_) for _ in a]))
print('\n'.join([''.join(i) for i in a]))


(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 = [list(map(str, input())) for _ in range(H)]
c = []
for li in a:
	if li != ['.'] * len(li):
		c.append(li)
b = []
for lc in zip(*c):
	if lc != ('.',) * len(lc):
		b.append(lc)
for ld in zip(*b):
	print(''.join(ld))


(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()


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


(H, W) = map(int, input().split())
a = [input() for i in range(H)]
b = []
for i in range(H):
	if '#' in a[i]:
		b.append(a[i])
ans = zip(*[i for i in zip(*b) if '#' in i])
for j in ans:
	print(*j, sep='')


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()


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 = [input() for i in range(h)]
a2 = [i for i in a if '#' in i]
a3 = [i for i in zip(*a2) if '#' in i]
for i in zip(*a3):
	print(''.join(i))


(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) = map(int, input().split())
grid = [list(input()) for i in range(h)]
for i in range(w)[::-1]:
	a = [grid[j][i] for j in range(h)]
	if not '#' in a:
		for j in range(h):
			del grid[j][i]
for i in grid:
	if '#' in i:
		print(*i, sep='')


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]))


(H, W) = map(int, input().split())
a = [input() for _ in range(H)]
a = [row for row in a if not all(map(lambda i: i == '.', row))]
a_T = [col for col in zip(*a) if not all(map(lambda i: i == '.', col))]
for row in zip(*a_T):
	print(''.join(row))


import sys
input()
for r in zip(*[c for c in zip(*[r for r in sys.stdin if '#' in r]) if '#' in c]):
	print(*r, sep='')


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 = [input() for i in range(H)]
B = []
for a in A:
	if not all([x == '.' for x in a]):
		B.append(a)
C = zip(*[b for b in zip(*B) if '#' in b])
for c in C:
	print(*c, sep='')


(H, W) = map(int, input().split())
a = [input() for _ in range(H)]
for i in range(H):
	if a[i].count('#') > 0:
		s = ''
		for j in range(W):
			if [A[j] for A in a].count('#') > 0:
				s += a[i][j]
		print(s)


(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))


f = lambda s: zip(*[t for t in s if '#' in t])
print(*map(''.join, f(f(open(0).readlines()))))


(H, W) = map(int, input().split())
a = [input() for _ in range(H)]
a = [i for i in zip(*a) if i.count('#')]
a = [''.join(i) for i in zip(*a) if i.count('#')]
print('\n'.join(a))


(H, W) = map(int, input().split())
m = []
for _ in [0] * H:
	l = input()
	if l != '.' * W:
		m += [l]
t = []
for j in range(W):
	f = 0
	for l in m:
		if l[j] != '.':
			f = 1
			break
	if f:
		t += [j]
for l in m:
	print(''.join([l[j] for j in t]))


(h, w) = map(int, input().split())
print(*[''.join(e) for e in zip(*[''.join(e) for e in zip(*[e for e in [input() for _ in [0] * h] if '#' in e]) if '#' in e])], sep='\n')


(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, *d) = open(0).read().split()
(h, w) = (int(h), int(w))
d = [i for i in d if '#' in i]
d = zip(*[j for j in zip(*d) if '#' in j])
print(*[''.join(p) for p in d], sep='\n')


(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)


(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))


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) = map(int, input().split())
a = [tuple(input()) for _ in range(h)]
b = [b for b in a if '#' in b]
c = zip(*[c for c in zip(*b) if '#' in c])
for d in c:
	print(*d, sep='')


(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())
s = []
for i in range(h):
	t = input()
	if t.count('.') != len(t):
		s.append(t)
l = [list(x) for x in zip(*s)]
t2 = []
for e in l:
	if e.count('.') != len(e):
		t2.append(e)
ans = [list(x) for x in zip(*t2)]
for e in ans:
	print(''.join(e))


import sys
input()
rows = [row for row in sys.stdin if '#' in row]
cols = [col for col in zip(*rows) if '#' in col]
for row in zip(*cols):
	print(*row, sep='')


(h, w) = map(int, input().split())
a = [input() for _ in range(h)]
l = []
ans = []
for i in a:
	if i == '.' * w:
		continue
	l.append(i)
for i in zip(*l):
	if ''.join(i) == '.' * len(i):
		continue
	ans.append(''.join(i))
for i in zip(*ans):
	print(''.join(i))


import sys
input = sys.stdin.readline
(H, W) = map(int, input().split())
arr = [[j for j in input().rstrip()] for i in range(H)]
b = [x for x in arr if '#' in x]
c = zip(*[x for x in zip(*b) if '#' in x])
for x in c:
	print(''.join(x))


(h, w) = [int(x) for x in input().split()]
a = [j for j in [input() for i in range(h)] if '#' in j]
a = [i for i in zip(*a) if '#' in i]
print('\n'.join([''.join(line) for line in zip(*a)]))


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 = [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)


(H, W) = map(int, input().split())
A = []
for h in range(H):
	a = input()
	if '#' in a:
		A.append(a)
A = [a for a in zip(*A) if '#' in a]
A = [a for a in zip(*A)]
for a in A:
	print(''.join(a))


(H, W) = map(int, input().split())
HW = [input() for _ in range(H)]
HW = [''.join(hw) for hw in zip(*HW) if hw.count('#') > 0]
HW = [''.join(hw) for hw in zip(*HW) if hw.count('#') > 0]
print('\n'.join(HW))


(h, w) = map(int, input().split())
a = []
for _ in [0] * h:
	ai = list(input())
	if '#' in ai:
		a.append(ai)
t = []
for wi in zip(*a):
	if '#' in wi:
		t.append(wi)
for ans in zip(*t):
	print(''.join(ans))


(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())
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]))


(h, w) = map(int, input().split())
a = [list(input()) for _ in range(h)]
ans = [i for i in a if '#' in i]
s = []
for i in range(w):
	t = 0
	for j in a:
		t += j[i] == '#'
	if t == 0:
		s += [i]
for i in s[::-1]:
	for j in ans:
		del j[i]
for i in ans:
	print(''.join(i))


(H, W) = map(int, input().split())
L = [list(input()) for _ in range(H)]
L = [l for l in L if '#' in l]
LL = list(zip(*L))
LL = [l for l in LL if '#' in l]
L = list(zip(*LL))
for l in L:
	print(''.join(l))


(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))


(H, W) = map(int, input().split())
A = []
for i in range(H):
	S = input()
	if S.count('.') != W:
		A.append(S)
c = zip(*[i for i in zip(*A) if '#' in i])
for d in c:
	print(''.join(d))


(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]))


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)


(h, w) = map(int, input().split())
As = [input() for _ in range(h)]
Bs = [x for x in As if '#' in x]
Cs = list(zip(*Bs))
Ds = [x for x in Cs if '#' in x]
ret = list(zip(*Ds))
for x in ret:
	print(*x, sep='')


(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(' '))
rows = [input() for _ in range(H)]
rows = [row for row in rows if '#' in row]
cols = list(zip(*rows))
cols = [col for col in cols if '#' in col]
rows = list(zip(*cols))
for row in rows:
	print(''.join(row))


(h, w) = map(int, input().split())
a = [list(input()) for _ in range(h)]
s = []
for i in a:
	if i.count('#') != 0:
		s.append(i)
a = [list(x) for x in zip(*s)]
s = []
for i in a:
	if i.count('#') != 0:
		s.append(i)
a = [list(x) for x in zip(*s)]
for i in a:
	print(''.join(i))


(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):
	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())
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)


(H, W) = map(int, input().split())
t = []
for _ in range(H):
	x = input()
	if x != '.' * W:
		t += [x]
num = len(t)
k = []
for s in zip(*t):
	s = ''.join(s)
	if s != '.' * num:
		k += [s]
for x in zip(*k):
	print(''.join(x))


(H, W) = map(int, input().split())
(S, U) = ([], [])
for _ in range(H):
	s = list(input())
	if '#' in s:
		S.append(s)
T = list(zip(*S))
for i in range(W):
	if '#' in T[i]:
		U.append(T[i])
res = []
for t in zip(*U):
	res.append(''.join(t))
print('\n'.join(res))


(h, w) = map(int, input().split())
a = [list(input()) for a in range(h)]
a2 = [b for b in a if b.count('#')]
x = [b for b in list(zip(*a2)) if b.count('#')]
y = list(zip(*x))
for a in y:
	print(''.join(a))


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


(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())
grid = []
for i in range(H):
	g = input()
	if '#' in g:
		grid.append(g)
ans = zip(*[i for i in zip(*grid) if '#' in i])
for j in ans:
	print(*j, sep='')


(h, w) = map(int, input().split())
l = []
for i in range(h):
	retu = list(input())
	if '#' in retu:
		l.append(retu)
ll = []
for i in zip(*l):
	if '#' in i:
		ll.append(i)
for i in zip(*ll):
	print(''.join(i))


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) = 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()


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('*', ''))


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())
s = [list(input()) for i in range(h)]
l = [x for x in s if '#' in x]
ans = []
for i in zip(*l):
	if '#' in i:
		ans.append(i)
an = zip(*ans)
for x in an:
	print(''.join(x))


(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())
l = [list(input()) for i in range(h)]
hs = set()
ws = set()
for i in range(h):
	for j in range(w):
		if l[i][j] == '#':
			hs.add(i)
			ws.add(j)
for i in hs:
	for j in ws:
		print(l[i][j], end='')
	print()


(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) = map(int, input().split())
a = [input() for _ in range(H)]
ans = [ch for ch in a if '#' in ch]
ans = [ch for ch in zip(*ans) if '#' in ch]
ans = [ch for ch in zip(*ans)]
for i in range(len(ans)):
	print(''.join(ans[i]))


(h, w) = map(int, input().split())
a = [list(input()) for _ in range(h)]
tmp1 = [i for i in a if set(i) != {'.'}]
tmp2 = [list(i) for i in zip(*tmp1)]
tmp3 = [i for i in tmp2 if set(i) != {'.'}]
ans = [list(i) for i in zip(*tmp3)]
for i in ans:
	print(''.join(i))


s = [f for f in open(0).read().split() if '#' in f]
s = [''.join([s[j][i] for j in range(len(s))]) for i in range(len(s[0]))]
s = [f for f in s if '#' in f]
s = [''.join([s[j][i] for j in range(len(s))]) for i in range(len(s[0]))]
print(*s, sep='\n')


(h, w) = map(int, input().split())
ban = []
banban = []
for i in range(h):
	tmp = input()
	if tmp != '.' * w:
		ban.append(list(tmp))
for zlist in zip(*ban):
	if '#' in zlist:
		banban.append(zlist)
for letter in zip(*banban):
	print(''.join(letter))


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


(H, W) = map(int, input().split())
A = [list(input()) for i in range(H)]
ww = set()
hh = set()
for h in range(H):
	for w in range(W):
		if A[h][w] == '#':
			ww.add(w)
			hh.add(h)
ww = sorted(list(ww))
for h in sorted(list(hh)):
	_ = ''
	for w in ww:
		_ += A[h][w]
	print(_)


(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]))


(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())
s = []
for i in range(n):
	t = input()
	if '#' in t:
		s.append(t)
s2 = [list(x) for x in zip(*s)]
s3 = []
for i in range(m):
	if '#' in s2[i]:
		s3.append(s2[i])
s4 = [list(x) for x in zip(*s3)]
for i in s4:
	print(''.join(map(str, i)))


(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 = [list(input()) for i in range(h)]
A1 = [a for a in A if '#' in a]
A2 = [a for a in zip(*A1) if '#' in a]
A3 = [a for a in zip(*A2)]
for a in A3:
	print(''.join(a))


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


(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())
a = []
for i in range(h):
	wi = input()
	if wi != '.' * w:
		a.append(wi)
b = zip(*[x for x in zip(*a) if '#' in x])
for i in b:
	print(''.join(i))


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


(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))


import sys
input = sys.stdin.readline
(h, w) = map(int, input().split())
f = lambda s: zip(*[column for column in s if '#' in column])
L = [input() for _ in range(h)]
for row in f(f(L)):
	print(*row, sep='', end='\n')


(h, w) = map(int, input().split())
l = [list(input()) for i in range(h)]
for i in reversed(range(h)):
	if all((j == '.' for j in l[i])):
		l.pop(i)
for i in reversed(range(w)):
	if all((j[i] == '.' for j in l)):
		for j in l:
			j.pop(i)
for i in l:
	print(''.join(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())
ll = [list(input()) for _ in range(h)]
lh = [h for h in ll if '#' in h]
lw = zip(*[w for w in zip(*lh) if '#' in w])
for l in lw:
	print(''.join(l))


(H, W) = map(int, input().split())
mas = [list(input()) for i in range(H)]
new_mas = [row for row in mas if '#' in row]
new_mas2 = [column for column in list(zip(*new_mas)) if '#' in column]
for i in list(zip(*new_mas2)):
	for j in i:
		print(j, end='')
	print()


(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
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) = map(int, input().split())
s = [input() for i in range(h)]
s = [s_x for s_x in s if '#' in s_x]
s = [s_y for s_y in zip(*s) if '#' in s_y]
for ss in zip(*s):
	print(''.join(ss))


(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 = []
answer = []
for _ in range(H):
	a = list(input())
	if '#' in a:
		A.append(a)
for a in list(zip(*A)):
	if '#' in a:
		answer.append(a)
for result in list(zip(*answer)):
	print(''.join(result))


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]))


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 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))


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))


(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)))


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())
s = []
for _ in range(h):
	a = input()
	if '#' in a:
		s.append(a)
d = []
for i in zip(*s):
	if '#' in i:
		d.append(i)
for j in zip(*d):
	print(*j, sep='')


(h, w) = map(int, input().split())
a = []
ans = []
for _ in range(h):
	aw = input()
	if set(aw) != {'.'}:
		a.append(aw)
for i in zip(*a):
	if set(i) != {'.'}:
		ans.append(''.join(list(i)))
for j in zip(*ans):
	print(''.join(list(j)))


(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
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(len(ans)):
	print(ans[i])


(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) = map(int, input().split())
g = [list(input()) for _ in range(h)]
gg = []
for l in zip(*g):
	if not all((x == '.' for x in l)):
		gg.append(l)
ggg = []
for l in zip(*gg):
	if not all((x == '.' for x in l)):
		print(''.join(l))


(h, w) = map(int, input().split())
m = []
for _ in range(h):
	l = input()
	if '#' in l:
		m.append(l)
m = list(zip(*m))
n = []
for i in m:
	if '#' in i:
		n.append(i)
n = list(zip(*n))
for i in n:
	for j in i:
		print(j, end='')
	print('')


(h, w) = map(int, input().split())
a1 = [[*input()] for _ in range(h)]
a2 = [i for (i, j) in enumerate(zip(*a1)) if j.count('.') == h]
[print(*[k for (l, k) in enumerate(j) if l not in a2], sep='') for j in [i for i in a1 if i.count('.') < w]]


(H, W) = map(int, input().split())
a = [list(input()) for i in range(H)]
b = []
c = []
for y in range(H):
	if '#' in a[y]:
		b.append(a[y])
for row in zip(*b):
	if '#' in row:
		c.append(row)
for row in zip(*c):
	print(''.join(row))


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) = map(int, input().split())
A = [list(input()) for _ in range(h)]
B = []
C = []
for Row in A:
	if set(Row) != {'.'}:
		B.append(Row)
B = [Row for Row in zip(*B)]
for Row in B:
	if set(Row) != {'.'}:
		C.append(Row)
for Row in zip(*C):
	print(''.join(Row))


(h, w) = map(int, input().split())
A = [[i for i in input()] for j in range(h)]
B = [a for a in A if '#' in a]
C = [b for b in zip(*B) if '#' in b]
for c in zip(*C):
	print(*c, sep='')


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]))


(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
	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) = [int(i) for i in input().split()]
maze = [list(input()) for _ in range(H)]
maze = [l for l in maze if '#' in l]
maze = list(zip(*maze))
maze = [l for l in maze if '#' in l]
maze = list(zip(*maze))
maze = [''.join(l) for l in maze]
print(*maze, sep='\n')


(h, w) = map(int, input().split())
p = [input() for _ in range(h)]
p = [row for row in p if not all(map(lambda i: i == '.', row))]
p = [col for col in zip(*p) if not all(map(lambda i: i == '.', col))]
for row in zip(*p):
	print(''.join(row))


(h, w) = map(int, input().split())
m = [list(input()) for _ in range(h)]
mr = [r for r in m if '#' in r]
mrc = [c for c in zip(*mr) if '#' in c]
print(*(''.join(row) for row in zip(*mrc)), sep='\n')


(H, W) = map(int, input().split())
M = [list(input()) for i in range(H)]
for i in range(H):
	if '#' in M[i]:
		s = []
		for x in range(W):
			t = [M[y][x] for y in range(H)]
			if '#' in t:
				s.append(M[i][x])
		print(''.join(s))


(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])


(h, w) = map(int, input().split())
sij = [[x for x in input()] for _ in range(h)]
sijd = [line for line in sij if '#' in line]
sijdd = zip(*[line for line in zip(*sijd) if '#' in line])
for line in sijdd:
	print(''.join(line))


(h, w) = map(int, input().split())
ls = [list(input()) for i in range(h)]
ls1 = [i for i in ls if '#' in i]
ls2 = [i for i in zip(*ls1) if '#' in i]
ls3 = [i for i in zip(*ls2)]
for i in ls3:
	print(''.join(i))


(h, w) = map(int, input().split())
rs = [input() for _ in range(h)]
rows = []
for r in rs:
	if '#' in r:
		rows.append(r)
ansrows = zip(*[c for c in zip(*rows) if '#' in c])
for r in list(ansrows):
	print(''.join(r))


(H, W) = map(int, input().split())
L = [list(input()) for _ in range(H)]
L1 = [x for x in L if '#' in x]
L2 = [x for x in zip(*L1) if '#' in x]
for t in zip(*L2):
	print(''.join(t))


(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) = (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
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
list_ans = [list(x) for x in zip(*list_tmp2)]
for i in range(0, len(list_ans)):
	print(''.join(list_ans[i]))


(h, w) = map(int, input().split())
grid = [list(input()) for i in range(h)]
for i in range(2):
	grid = [col for col in grid if '#' in col]
	grid = list(map(list, zip(*grid)))
for g in grid:
	print(''.join(g))


(h, w) = [int(_) for _ in input().split()]
a = [input() for i in range(h)]
a = [''.join(row) for row in zip(*a) if row.count('#') > 0]
a = [''.join(row) for row in zip(*a) if row.count('#') > 0]
print('\n'.join(a))


(H, W) = map(int, input().split())
tmp = []
for i in range(H):
	l = input()
	if '#' in l:
		tmp.append(l)
ans = []
for l in zip(*tmp):
	if '#' in l:
		ans.append(''.join(l))
for l in zip(*ans):
	print(''.join(l))


(h, w) = map(int, input().split())
a = []
A = [[i for i in input()] for _ in range(h)]
B = [x for x in A if '#' in x]
C = zip(*[y for y in zip(*B) if '#' in y])
for d in C:
	print(''.join(d))


(H, W) = map(int, input().split())
A = [input() for _ in range(H)]
tmp = []
for a in zip(*A):
	if a.count('#') > 0:
		tmp.append(''.join(a))
tmp2 = []
for t in zip(*tmp):
	if t.count('#') > 0:
		tmp2.append(''.join(t))
print('\n'.join(tmp2))


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


(h, w) = map(int, input().split())
a = [input() for i in range(h)]
while '.' * w in a:
	a.remove('.' * w)
hh = len(a)
a = [''.join(h_line) for h_line in zip(*a)]
while '.' * hh in a:
	a.remove('.' * hh)
for line in zip(*a):
	print(''.join(line))