H,W=map(int,input().split())
S=[[-9999 if s == "#" else 0 for s in input()] for _ in range(H)]
for h in range(H):
	for w in range(W):
		if S[h][w] < 0:
			for xh in range(max(0, h-1), min(H, h+2)):
				for xw in range(max(0, w-1), min(W, w+2)):
					if xh != h or xw != w:
						S[xh][xw] += 1
print("\n".join(["".join(["#" if x < 0 else str(x) for x in row]) for row in S]))
