import sys
h, w = map(int, input().split())

s = [["." for _ in range(w+2)]] + [["."]+list(input())+["."] for _ in range(h)] + [["." for _ in range(w+2)]]
for r in range(1, h+1):
  for c in range(1, w+1):
    if s[r][c] == ".":
      s[r][c] = str([s[r+dr][c+dc] for dr in [-1, 0, 1] for dc in [-1, 0, 1]].count("#"))
for r in range(1, h+1):
  print("".join(s[r][1:w+1]))
