q=list(map(int,input().split()))

grid=[]

def k1(x,y):

  z=[]

  if y[0]+1<x[0]:

    z.append([y[0]+1,y[1]])

    if y[1]+1<x[1]:#

      z.append([y[0]+1,y[1]+1])

    if y[1]-1>=0:

      z.append([y[0]+1,y[1]-1])

  if y[0]-1>=0:

    z.append([y[0]-1,y[1]])

    if y[1]+1<x[1]:#

      z.append([y[0]-1,y[1]+1])

    if y[1]-1>=0:

      z.append([y[0]-1,y[1]-1])    

  if y[1]+1<x[1]:

    z.append([y[0],y[1]+1])

  if y[1]-1>=0:

    z.append([y[0],y[1]-1])

  return(z)

for i in range(q[0]):

    y=eval(input())



    grid.append([i for i in y])

  

for i in range(q[0]):

    for j in range(q[1]):

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

            

          

            kh=k1(q,[i,j])

            

            count=0

            

            for k in range(len(kh)) :

                

                

                if grid[kh[k][0]][kh[k][1]] == '#' :

                  count+=1

            grid[i][j]=count      

                

for i in range(q[0]):

    pr=''

    for j in range(q[1]):

        pr=pr+str(grid[i][j])

    print(pr)



a,b = list(map(int,input().split()))

bo = []

bo.append("."*(b+2))

for i in range(a):

    s = eval(input())

    s = "." + s + "."

    s = list(s)

    bo.append(s)

bo.append("."*(b+2))



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

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



for i in range(1,a+1):

    for j in range(1,b+1):

        cnt = 0

        if bo[i][j] == "#":

            continue

        for k in range(8):

            ch = bo[i-dx[k]][j-dy[k]]

            if ch == "#":

                cnt += 1

        bo[i][j] = str(cnt)



for i in range(1,a+1):

    print(("".join(bo[i][1:-1])))

q = list(map(int, input().split()))
grid = []


def k1(x, y):
    z = []
    if y[0] + 1 < x[0]:
        z.append([y[0] + 1, y[1]])
        if y[1] + 1 < x[1]:  #
            z.append([y[0] + 1, y[1] + 1])
        if y[1] - 1 >= 0:
            z.append([y[0] + 1, y[1] - 1])
    if y[0] - 1 >= 0:
        z.append([y[0] - 1, y[1]])
        if y[1] + 1 < x[1]:  #
            z.append([y[0] - 1, y[1] + 1])
        if y[1] - 1 >= 0:
            z.append([y[0] - 1, y[1] - 1])
    if y[1] + 1 < x[1]:
        z.append([y[0], y[1] + 1])
    if y[1] - 1 >= 0:
        z.append([y[0], y[1] - 1])
    return z


for i in range(q[0]):
    y = eval(input())
    grid.append([i for i in y])
for i in range(q[0]):
    for j in range(q[1]):
        if grid[i][j] == ".":
            kh = k1(q, [i, j])
            count = 0
            for k in range(len(kh)):
                if grid[kh[k][0]][kh[k][1]] == "#":
                    count += 1
            grid[i][j] = count
for i in range(q[0]):
    pr = ""
    for j in range(q[1]):
        pr = pr + str(grid[i][j])
    print(pr)

a, b = list(map(int, input().split()))
bo = []
bo.append("." * (b + 2))
for i in range(a):
    s = eval(input())
    s = "." + s + "."
    s = list(s)
    bo.append(s)
bo.append("." * (b + 2))
dx = [-1, -1, -1, 1, 1, 1, 0, 0]
dy = [-1, 0, 1, -1, 0, 1, 1, -1]
for i in range(1, a + 1):
    for j in range(1, b + 1):
        cnt = 0
        if bo[i][j] == "#":
            continue
        for k in range(8):
            ch = bo[i - dx[k]][j - dy[k]]
            if ch == "#":
                cnt += 1
        bo[i][j] = str(cnt)
for i in range(1, a + 1):
    print(("".join(bo[i][1:-1])))

-q = list(map(int, input().split())) -grid = [] - - -def k1(x, y): -    z = [] -    if y[0] + 1 < x[0]: -        z.append([y[0] + 1, y[1]]) -        if y[1] + 1 < x[1]:  # -            z.append([y[0] + 1, y[1] + 1]) -        if y[1] - 1 >= 0: -            z.append([y[0] + 1, y[1] - 1]) -    if y[0] - 1 >= 0: -        z.append([y[0] - 1, y[1]]) -        if y[1] + 1 < x[1]:  # -            z.append([y[0] - 1, y[1] + 1]) -        if y[1] - 1 >= 0: -            z.append([y[0] - 1, y[1] - 1]) -    if y[1] + 1 < x[1]: -        z.append([y[0], y[1] + 1]) -    if y[1] - 1 >= 0: -        z.append([y[0], y[1] - 1]) -    return z - - -for i in range(q[0]): -    y = eval(input()) -    grid.append([i for i in y]) -for i in range(q[0]): -    for j in range(q[1]): -        if grid[i][j] == ".": -            kh = k1(q, [i, j]) -            count = 0 -            for k in range(len(kh)): -                if grid[kh[k][0]][kh[k][1]] == "#": -                    count += 1 -            grid[i][j] = count -for i in range(q[0]): -    pr = "" -    for j in range(q[1]): -        pr = pr + str(grid[i][j]) -    print(pr) +a, b = list(map(int, input().split())) +bo = [] +bo.append("." * (b + 2)) +for i in range(a): +    s = eval(input()) +    s = "." + s + "." +    s = list(s) +    bo.append(s) +bo.append("." * (b + 2)) +dx = [-1, -1, -1, 1, 1, 1, 0, 0] +dy = [-1, 0, 1, -1, 0, 1, 1, -1] +for i in range(1, a + 1): +    for j in range(1, b + 1): +        cnt = 0 +        if bo[i][j] == "#": +            continue +        for k in range(8): +            ch = bo[i - dx[k]][j - dy[k]] +            if ch == "#": +                cnt += 1 +        bo[i][j] = str(cnt) +for i in range(1, a + 1): +    print(("".join(bo[i][1:-1])))