from itertools import product





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

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

for i in range(H):

    for j in range(W):

        m = product([0, 1, -1], repeat=2)

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

            S[i][j] = 0

            for ii, jj in m:

                iii = i + ii

                jjj = j + jj

                if 0 <= iii < H and 0 <= jjj < W:

                    if S[iii][jjj] == '#':

                        S[i][j] += 1

            S[i][j] = str(S[i][j])

for s in S:

    print((('').join(s)))
from itertools import product





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

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

m = list(product([0, 1, -1], repeat=2))

for i in range(H):

    for j in range(W):

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

            S[i][j] = 0

            for ii, jj in m:

                iii = i + ii

                jjj = j + jj

                if 0 <= iii < H and 0 <= jjj < W:

                    if S[iii][jjj] == '#':

                        S[i][j] += 1

            S[i][j] = str(S[i][j])

for s in S:

    print((('').join(s)))
from itertools import product

H, W = list(map(int, input().split()))
S = [list(eval(input())) for _ in range(H)]
for i in range(H):
    for j in range(W):
        m = product([0, 1, -1], repeat=2)
        if S[i][j] == ".":
            S[i][j] = 0
            for ii, jj in m:
                iii = i + ii
                jjj = j + jj
                if 0 <= iii < H and 0 <= jjj < W:
                    if S[iii][jjj] == "#":
                        S[i][j] += 1
            S[i][j] = str(S[i][j])
for s in S:
    print((("").join(s)))

from itertools import product

H, W = list(map(int, input().split()))
S = [list(eval(input())) for _ in range(H)]
m = list(product([0, 1, -1], repeat=2))
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            S[i][j] = 0
            for ii, jj in m:
                iii = i + ii
                jjj = j + jj
                if 0 <= iii < H and 0 <= jjj < W:
                    if S[iii][jjj] == "#":
                        S[i][j] += 1
            S[i][j] = str(S[i][j])
for s in S:
    print((("").join(s)))

+m = list(product([0, 1, -1], repeat=2)) -        m = product([0, 1, -1], repeat=2)