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

S = [input() for _ in range(H)]

answer = [[0 if cell == '.' else '#' for cell in row] for row in S]



import itertools

for i in range(H):

  for j in range(W):

    if S[i][j] != '#':

      continue

    for dx,dy in itertools.product([-1,0,1],repeat=2):

      x = i+dx

      y = j+dy

      if x < 0 or x >= H:

        continue

      if y < 0 or y >= W:

        continue

      if S[x][y] == '#':

        continue

      answer[x][y] += 1



      

for row in answer:

  print(*row,sep='')

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

S=[eval(input()) for _ in range(H)]

for i in range(H):

  T=''

  for j in range(W):

    if S[i][j] == '#':

      T+='#'

    else:

      T+=str(sum([x[max(0,j-1):min(j+2,W)].count('#') for x in S[max(0,i-1):min(i+2,H)]]))

    

  print(T)   

H, W = map(int, input().split())
S = [input() for _ in range(H)]
answer = [[0 if cell == "." else "#" for cell in row] for row in S]
import itertools

for i in range(H):
    for j in range(W):
        if S[i][j] != "#":
            continue
        for dx, dy in itertools.product([-1, 0, 1], repeat=2):
            x = i + dx
            y = j + dy
            if x < 0 or x >= H:
                continue
            if y < 0 or y >= W:
                continue
            if S[x][y] == "#":
                continue
            answer[x][y] += 1
for row in answer:
    print(*row, sep="")

H, W = list(map(int, input().split()))
S = [eval(input()) for _ in range(H)]
for i in range(H):
    T = ""
    for j in range(W):
        if S[i][j] == "#":
            T += "#"
        else:
            T += str(
                sum(
                    [
                        x[max(0, j - 1) : min(j + 2, W)].count("#")
                        for x in S[max(0, i - 1) : min(i + 2, H)]
                    ]
                )
            )
    print(T)

-H, W = map(int, input().split()) -S = [input() for _ in range(H)] -answer = [[0 if cell == "." else "#" for cell in row] for row in S] -import itertools - +H, W = list(map(int, input().split())) +S = [eval(input()) for _ in range(H)] +    T = "" -        if S[i][j] != "#": -            continue -        for dx, dy in itertools.product([-1, 0, 1], repeat=2): -            x = i + dx -            y = j + dy -            if x < 0 or x >= H: -                continue -            if y < 0 or y >= W: -                continue -            if S[x][y] == "#": -                continue -            answer[x][y] += 1 -for row in answer: -    print(*row, sep="") +        if S[i][j] == "#": +            T += "#" +        else: +            T += str( +                sum( +                    [ +                        x[max(0, j - 1) : min(j + 2, W)].count("#") +                        for x in S[max(0, i - 1) : min(i + 2, H)] +                    ] +                ) +            ) +    print(T)