import numpy as np

h,w=list(map(int,input().split()))

L=[[i for i in eval(input())] for i in range(h)]

L_first=np.zeros((2,w),dtype=str)

L_first2=np.zeros((1,1),dtype=str)

L=np.array(L,dtype=str)

L=np.insert(L_first,1,L,axis=0)

L=np.insert(L,0,L_first2,axis=1)

L=np.insert(L,w+1,L_first2,axis=1)

ans=np.zeros((h,w),dtype=str)

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

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

        num = 0

        if L[i][j]==".":

            L2=L[i-1:i+2,j-1:j+2]

            ans[i-1][j-1]=np.sum(L2=="#")

        else:ans[i-1][j-1]="#"

for i in range(h):

    print(("".join(ans[i])))
H, W = list(map(int, input().split()))

src = [list(eval(input())) for i in range(H)]

ans=src



dxy = [(-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1)]

for y in range(H):

    for x in range(W):

        if src[y][x] == '#': continue

        c = 0

        for dx, dy in dxy:

            if x + dx < 0 or x + dx > W - 1 or y + dy < 0 or y + dy > H - 1: continue

            if src[y + dy][x + dx] == '#': c += 1

        ans[y][x] = c



for row in ans:

    print((''.join(list(map(str, row)))))
import numpy as np

h, w = list(map(int, input().split()))
L = [[i for i in eval(input())] for i in range(h)]
L_first = np.zeros((2, w), dtype=str)
L_first2 = np.zeros((1, 1), dtype=str)
L = np.array(L, dtype=str)
L = np.insert(L_first, 1, L, axis=0)
L = np.insert(L, 0, L_first2, axis=1)
L = np.insert(L, w + 1, L_first2, axis=1)
ans = np.zeros((h, w), dtype=str)
for i in range(1, h + 1):
    for j in range(1, w + 1):
        num = 0
        if L[i][j] == ".":
            L2 = L[i - 1 : i + 2, j - 1 : j + 2]
            ans[i - 1][j - 1] = np.sum(L2 == "#")
        else:
            ans[i - 1][j - 1] = "#"
for i in range(h):
    print(("".join(ans[i])))

H, W = list(map(int, input().split()))
src = [list(eval(input())) for i in range(H)]
ans = src
dxy = [(-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1)]
for y in range(H):
    for x in range(W):
        if src[y][x] == "#":
            continue
        c = 0
        for dx, dy in dxy:
            if x + dx < 0 or x + dx > W - 1 or y + dy < 0 or y + dy > H - 1:
                continue
            if src[y + dy][x + dx] == "#":
                c += 1
        ans[y][x] = c
for row in ans:
    print(("".join(list(map(str, row)))))

-import numpy as np - -h, w = list(map(int, input().split())) -L = [[i for i in eval(input())] for i in range(h)] -L_first = np.zeros((2, w), dtype=str) -L_first2 = np.zeros((1, 1), dtype=str) -L = np.array(L, dtype=str) -L = np.insert(L_first, 1, L, axis=0) -L = np.insert(L, 0, L_first2, axis=1) -L = np.insert(L, w + 1, L_first2, axis=1) -ans = np.zeros((h, w), dtype=str) -for i in range(1, h + 1): -    for j in range(1, w + 1): -        num = 0 -        if L[i][j] == ".": -            L2 = L[i - 1 : i + 2, j - 1 : j + 2] -            ans[i - 1][j - 1] = np.sum(L2 == "#") -        else: -            ans[i - 1][j - 1] = "#" -for i in range(h): -    print(("".join(ans[i]))) +H, W = list(map(int, input().split())) +src = [list(eval(input())) for i in range(H)] +ans = src +dxy = [(-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1)] +for y in range(H): +    for x in range(W): +        if src[y][x] == "#": +            continue +        c = 0 +        for dx, dy in dxy: +            if x + dx < 0 or x + dx > W - 1 or y + dy < 0 or y + dy > H - 1: +                continue +            if src[y + dy][x + dx] == "#": +                c += 1 +        ans[y][x] = c +for row in ans: +    print(("".join(list(map(str, row)))))