# -*- coding: utf-8 -*-
import sys

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

S = []
for i in range(0, H):
	S.append(raw_input())

ans = [["" for i in range(W)] for j in range(H)]

dx = (1, 0, -1,  0, 1, -1, -1,  1)
dy = (0, 1,  0, -1, 1,  1, -1, -1)

for i in range(0, H):
	for j in range(0, W):
		if S[i][j] == "#":
			ans[i][j] = "#"
			continue

		count = 0
		for d in range(0, 8):
			ni = i + dy[d]
			nj = j + dx[d]

			if ni < 0 or H <= ni: continue
			if nj < 0 or W <= nj: continue
			if S[ni][nj] == "#": count+=1

		ans[i][j] = str(count)


for i in range(0, H):
	for j in range(0, W):
		sys.stdout.write(ans[i][j])
	print
