h,w = map(int, input().strip().split())
F = []
for _ in range(h):
  F.append(list(input()))
 
for i in range(h):
  for j in range(w):
    if F[i][j] == ".":
      u = max(i-1,0)
      d = min(i+2,h)
      l = max(j-1,0)
      r = min(j+2,w)
      n = 0
      for line in F[u:d]:
          n += line[l:r].count("#")
      F[i][j] = str(n)

for line in F:
    print("".join(line))