H, W = map(int, input().split())

A = ["." * (W+2)] + [("." + input()) + "." for _ in range(H)] + ["." * (W+2)]

for i in range(1,H+1):
  for j in range(1,W+1):
    if A[i][j] == "#":
      L ="#"
    else:
      L =sum([1 for x in range(-1, 2) for y in range(-1, 2) if A[i+x][j+y] == "#"])
    print (L, end = "")
  print()
