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

li = [".." + "." * w]
for i in range(h):
  li.append("." + input() + ".")
li.append(".." + "." * w)

for i in range(1, h+1):
  ans = ""
  for j in range(1, w+1):
    if li[i][j] =="#":
      ans+="#"
    else:
      count = 0
      for a in [-1, 0, 1]:
        for b in [-1, 0, 1]:
          if li[i+a][j+b] == "#":
            count += 1
      ans += str(count)
  print(ans)