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

P=[]



for i in range(H):

  S=list(eval(input()))

  P.append(S)





dx=[-1,-1,-1,0,1,1,1,0]

dy=[-1,0,1,1,1,0,-1,-1]



for i in range(H):

  for j in range(W):

    if P[i][j]=='.':

      count=0

      for k in range(8):

        x=i+dx[k]

        y=j+dy[k]

        if x<H and x>=0 and y<W and y>=0 and P[x][y]=='#':

          count+=1

        P[i][j]=count

          

for i in range(H):

  answer=""

  for j in range(W):

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

      answer+="#"

    else:

      answer+=str(P[i][j])

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

Mine=[]

for i in range(H):

  Mine.append(list(eval(input())))

for i in range(H):

  answer=[]

  for j in range(W):

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

      answer.append('#')

    else:

      count=0

      if i!=0:

        if j!=0:

          if Mine[i-1][j-1]=='#':

            count+=1

        if j!=W-1:

          if Mine[i-1][j+1]=='#':

            count+=1

        if Mine[i-1][j]=='#':

          count+=1

      if i!=H-1:

        if j!=0:

          if Mine[i+1][j-1]=='#':

            count+=1

        if j!=W-1:

          if Mine[i+1][j+1]=='#':

            count+=1

        if Mine[i+1][j]=='#':

          count+=1

      if j!=0:

        if Mine[i][j-1]=='#':

          count+=1

      if j!=W-1:

        if Mine[i][j+1]=='#':

          count+=1

      answer.append(str(count))

  print(("".join(answer)))
H, W = list(map(int, input().split()))
P = []
for i in range(H):
    S = list(eval(input()))
    P.append(S)
dx = [-1, -1, -1, 0, 1, 1, 1, 0]
dy = [-1, 0, 1, 1, 1, 0, -1, -1]
for i in range(H):
    for j in range(W):
        if P[i][j] == ".":
            count = 0
            for k in range(8):
                x = i + dx[k]
                y = j + dy[k]
                if x < H and x >= 0 and y < W and y >= 0 and P[x][y] == "#":
                    count += 1
                P[i][j] = count
for i in range(H):
    answer = ""
    for j in range(W):
        if P[i][j] == "#":
            answer += "#"
        else:
            answer += str(P[i][j])
    print(answer)

H, W = list(map(int, input().split()))
Mine = []
for i in range(H):
    Mine.append(list(eval(input())))
for i in range(H):
    answer = []
    for j in range(W):
        if Mine[i][j] == "#":
            answer.append("#")
        else:
            count = 0
            if i != 0:
                if j != 0:
                    if Mine[i - 1][j - 1] == "#":
                        count += 1
                if j != W - 1:
                    if Mine[i - 1][j + 1] == "#":
                        count += 1
                if Mine[i - 1][j] == "#":
                    count += 1
            if i != H - 1:
                if j != 0:
                    if Mine[i + 1][j - 1] == "#":
                        count += 1
                if j != W - 1:
                    if Mine[i + 1][j + 1] == "#":
                        count += 1
                if Mine[i + 1][j] == "#":
                    count += 1
            if j != 0:
                if Mine[i][j - 1] == "#":
                    count += 1
            if j != W - 1:
                if Mine[i][j + 1] == "#":
                    count += 1
            answer.append(str(count))
    print(("".join(answer)))

-P = [] +Mine = [] -    S = list(eval(input())) -    P.append(S) -dx = [-1, -1, -1, 0, 1, 1, 1, 0] -dy = [-1, 0, 1, 1, 1, 0, -1, -1] +    Mine.append(list(eval(input()))) +    answer = [] -        if P[i][j] == ".": +        if Mine[i][j] == "#": +            answer.append("#") +        else: -            for k in range(8): -                x = i + dx[k] -                y = j + dy[k] -                if x < H and x >= 0 and y < W and y >= 0 and P[x][y] == "#": +            if i != 0: +                if j != 0: +                    if Mine[i - 1][j - 1] == "#": +                        count += 1 +                if j != W - 1: +                    if Mine[i - 1][j + 1] == "#": +                        count += 1 +                if Mine[i - 1][j] == "#": -                P[i][j] = count -for i in range(H): -    answer = "" -    for j in range(W): -        if P[i][j] == "#": -            answer += "#" -        else: -            answer += str(P[i][j]) -    print(answer) +            if i != H - 1: +                if j != 0: +                    if Mine[i + 1][j - 1] == "#": +                        count += 1 +                if j != W - 1: +                    if Mine[i + 1][j + 1] == "#": +                        count += 1 +                if Mine[i + 1][j] == "#": +                    count += 1 +            if j != 0: +                if Mine[i][j - 1] == "#": +                    count += 1 +            if j != W - 1: +                if Mine[i][j + 1] == "#": +                    count += 1 +            answer.append(str(count)) +    print(("".join(answer)))