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

l = []
for i in range(H):
  l.append(list(input()))

for h in range(H):
  for w in range(W):
    if l[h][w] == "#":
      continue
    cnt = 0
    for x in range(-1, 2):
      for y in range(-1, 2):
        if h+x >= 0 and w+y >= 0 and h+x < H and w+y < W:
          if l[h+x][w+y] == "#":
            cnt = cnt + 1
    l[h][w] = str(cnt)

for i in l:
  print("".join(i))
