import numpy as np

ans = []

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

S = []

S.append('.'*(W+2))

for i in range(H):

    S.append('.'+eval(input()) + '.')

S.append('.'*(W+2))



for y in range(1, H+1):

    for x in range(1, W+1):

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

            cnt = S[y][x-1].count('#')+S[y][x+1].count('#')+S[y-1][x-1:x+2].count('#')+S[y+1][x-1:x+2].count('#')

            ans.append(str(cnt))

        else:

            ans.append('#')

np_ans = np.array(ans)

re_ans = np.reshape(np_ans, (H, W))

for i in re_ans:

    print((''.join(i)))
H, W = list(map(int, input().split()))

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

ans = [['#' for i in range(W)] for i in range(H)]

for x in range(W):

    for y in range(H):

        num = 0

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

            for dx, dy in [1, 0], [-1, 0], [0, 1], [0, -1], [1, 1], [-1, -1], [1, -1], [-1, 1]:

                if 0 <= y + dy <= H - 1 and 0 <= x + dx <= W - 1:

                    if S[y + dy][x + dx] == '#':

                        num += 1

            ans[y][x] = str(num)



for i in ans:

    print((''.join(i)))
import numpy as np

ans = []
H, W = list(map(int, input().split()))
S = []
S.append("." * (W + 2))
for i in range(H):
    S.append("." + eval(input()) + ".")
S.append("." * (W + 2))
for y in range(1, H + 1):
    for x in range(1, W + 1):
        if S[y][x] == ".":
            cnt = (
                S[y][x - 1].count("#")
                + S[y][x + 1].count("#")
                + S[y - 1][x - 1 : x + 2].count("#")
                + S[y + 1][x - 1 : x + 2].count("#")
            )
            ans.append(str(cnt))
        else:
            ans.append("#")
np_ans = np.array(ans)
re_ans = np.reshape(np_ans, (H, W))
for i in re_ans:
    print(("".join(i)))

H, W = list(map(int, input().split()))
S = [eval(input()) for i in range(H)]
ans = [["#" for i in range(W)] for i in range(H)]
for x in range(W):
    for y in range(H):
        num = 0
        if S[y][x] == ".":
            for dx, dy in (
                [1, 0],
                [-1, 0],
                [0, 1],
                [0, -1],
                [1, 1],
                [-1, -1],
                [1, -1],
                [-1, 1],
            ):
                if 0 <= y + dy <= H - 1 and 0 <= x + dx <= W - 1:
                    if S[y + dy][x + dx] == "#":
                        num += 1
            ans[y][x] = str(num)
for i in ans:
    print(("".join(i)))

-import numpy as np - -ans = [] -S = [] -S.append("." * (W + 2)) -for i in range(H): -    S.append("." + eval(input()) + ".") -S.append("." * (W + 2)) -for y in range(1, H + 1): -    for x in range(1, W + 1): +S = [eval(input()) for i in range(H)] +ans = [["#" for i in range(W)] for i in range(H)] +for x in range(W): +    for y in range(H): +        num = 0 -            cnt = ( -                S[y][x - 1].count("#") -                + S[y][x + 1].count("#") -                + S[y - 1][x - 1 : x + 2].count("#") -                + S[y + 1][x - 1 : x + 2].count("#") -            ) -            ans.append(str(cnt)) -        else: -            ans.append("#") -np_ans = np.array(ans) -re_ans = np.reshape(np_ans, (H, W)) -for i in re_ans: +            for dx, dy in ( +                [1, 0], +                [-1, 0], +                [0, 1], +                [0, -1], +                [1, 1], +                [-1, -1], +                [1, -1], +                [-1, 1], +            ): +                if 0 <= y + dy <= H - 1 and 0 <= x + dx <= W - 1: +                    if S[y + dy][x + dx] == "#": +                        num += 1 +            ans[y][x] = str(num) +for i in ans: