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

Ss = [[-1 if c == "#" else 0 for c in input()] for _ in range(H)]

def plus(i, j):
  if 0 <= i < H and 0 <= j < W:
    if Ss[i][j] >= 0:
      Ss[i][j] += 1

for i in range(H):
  for j in range(W):
    for x, y in ((x,y) for x in range(-1, 2) for y in range(-1, 2):
      if x != 0 or y != 0:
        plus(i, j)

for i in range(H):
  for j in range(W):
    print("#" if Ss[i][j] == -1 else Ss[i][j], end="")
