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

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

			# i-1
			if i-1 >= 0:
				if j-1 >= 0:
					if S[i-1][j-1] == "#":
						count+=1
				if S[i-1][j] == "#":
					count+=1
				if j+1 < W:
					if S[i-1][j+1] == "#":
						count+=1
			# i
			if j-1 >= 0:
				if S[i][j-1] == "#":
					count+=1
			if j+1 < W:
				if S[i][j+1] == "#":
					count+=1
			# i+1
			if i+1 < H:
				if j-1 >= 0:
					if S[i+1][j-1] == "#":
						count+=1
				if S[i+1][j] == "#":
					count+=1
				if j+1 < W:
					if S[i+1][j+1] == "#":
						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
