H,W = map(int, input().split())
S = []

for _ in range(H):
  S.append([s for s in input()])

for h in range(H):
  for w in range(W):
    if S[h][w] == ".":
      a = 0
      for x in [-1, 0, 1]:
        for y in [-1, 0, 1]:
          if 0 <= h+x < H and 0 <= w+y < W:
            if S[h+x][w+y] == "#":
              a += 1
      S[h][w] = str(a)

for _ in range(H):
  print("".join(S[_]))