import copy



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

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

ans = copy.deepcopy(S)



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

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



for i in range(H):

    for j in range(W):

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

            cnt = 0

            for dir in range(8):

                if 0 <= i + dy[dir] < H and 0 <= j + dx[dir] < W:

                    cnt += (S[i + dy[dir]][j + dx[dir]] == "#")

                

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

for h in range(H):

    print(("".join(ans[h])))

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

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



def bomb_count(hi, wi):

    cnt = 0

    for i in range(-1, 2):

        for j in range(-1, 2):

            if (0 <= (hi + i) <= (H-1)) and (0 <= (wi + j) <= (W-1)):

                if S[hi+i][wi+j] == "#":

                    cnt += 1

    return cnt





for hi in range(H):

    for wi in range(W):

        masu = S[hi][wi]

        if masu == ".":

            S[hi][wi] = str(bomb_count(hi, wi))



for hi in range(H):

    row = S[hi]

    print(("".join(row)))
import copy

H, W = list(map(int, input().split()))
S = [list(eval(input())) for _ in range(H)]
ans = copy.deepcopy(S)
dx = [1, 1, 0, -1, -1, -1, 0, 1]
dy = [0, 1, 1, 1, 0, -1, -1, -1]
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            cnt = 0
            for dir in range(8):
                if 0 <= i + dy[dir] < H and 0 <= j + dx[dir] < W:
                    cnt += S[i + dy[dir]][j + dx[dir]] == "#"
            ans[i][j] = str(cnt)
for h in range(H):
    print(("".join(ans[h])))

H, W = list(map(int, input().split()))
S = [list(eval(input())) for _ in range(H)]


def bomb_count(hi, wi):
    cnt = 0
    for i in range(-1, 2):
        for j in range(-1, 2):
            if (0 <= (hi + i) <= (H - 1)) and (0 <= (wi + j) <= (W - 1)):
                if S[hi + i][wi + j] == "#":
                    cnt += 1
    return cnt


for hi in range(H):
    for wi in range(W):
        masu = S[hi][wi]
        if masu == ".":
            S[hi][wi] = str(bomb_count(hi, wi))
for hi in range(H):
    row = S[hi]
    print(("".join(row)))

-import copy - -ans = copy.deepcopy(S) -dx = [1, 1, 0, -1, -1, -1, 0, 1] -dy = [0, 1, 1, 1, 0, -1, -1, -1] -for i in range(H): -    for j in range(W): -        if S[i][j] == ".": -            cnt = 0 -            for dir in range(8): -                if 0 <= i + dy[dir] < H and 0 <= j + dx[dir] < W: -                    cnt += S[i + dy[dir]][j + dx[dir]] == "#" -            ans[i][j] = str(cnt) -for h in range(H): -    print(("".join(ans[h]))) + + +def bomb_count(hi, wi): +    cnt = 0 +    for i in range(-1, 2): +        for j in range(-1, 2): +            if (0 <= (hi + i) <= (H - 1)) and (0 <= (wi + j) <= (W - 1)): +                if S[hi + i][wi + j] == "#": +                    cnt += 1 +    return cnt + + +for hi in range(H): +    for wi in range(W): +        masu = S[hi][wi] +        if masu == ".": +            S[hi][wi] = str(bomb_count(hi, wi)) +for hi in range(H): +    row = S[hi] +    print(("".join(row)))