H, W = map(int, input().split())
data = []
for i in range(H):
  S.append(input())
# 参考https://atcoder.jp/contests/abc075/submissions/5409794
for i in range(H):
  for j in range(W):
    if S[i][j] == ".":
      cnt = 0
      if i != 0:
        cnt += S[i-1][min(0, j-1) : min(j+1, W-1) + 1].count("#")
      cnt += S[i][min(0, j-1) : min(j+1, W-1) + 1].count("#")
      if i != H-1:
        cnt += S[i+1][min(0, j-1) : min(j+1, W-1) + 1].count("#")
      S[i][j] = cnt
for i in range(H):
	print("".join(S[i]))