H, W = map(int, input().split())
S = [list(input()) for i in range(H)]
ans = [[0] * (W + 2) for i in range(H + 2)]
mine = []
for i in range(H):
	for j in range(W):
		if S[i][j] != "#":
			continue
		mine.append((i, j))
		for v in range(3):
			for h in range(3):
				ans[i + v][j + h] += 1

for i, j in mine:
	ans[i + 1][j + 1] = "#"
for l in ans[1: H + 1]:
	print("".join(map(str, l[1: W + 1])))
