h, w = map(int, input().split())
s = [ input() for _ in range(h) ]
l = [[0]*(w+2) for _ in range(h+2)]
for i in range(h):
  for j in range(w):
    if s[i][j] == "#":
      for y in range(i, i+3):
        for x in range(j, j+3):
          if l[y][x] != "#":
            l[y][x] += 1
      l[i+1][j+1] = "#"
for i in range(1, h+1):
  print(*l[i][1:w+1], sep="")