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

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

ans = [[''] * W for _ in range(H)]

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

for h in range(H):

    for w in range(W):

        if S[h][w] == '#':

            ans[h][w] = '#'

        else:

            ans[h][w] = str(sum([S[h + nh][w + nw] == "#" for nh, nw in N if 0 <= h + nh < H and 0 <= w + nw < W]))



for h in range(H):

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

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

S = ['.' * (W + 2)] + ['.' + eval(input()) + '.' for _ in range(H)] + ['.' * (W + 2)]

ans = [[] for _ in range(H)]

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

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

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

        if S[h][w] == '#':

            ans[h - 1].append('#')

        else:

            ans[h - 1].append(str(sum([S[h + nh][w + nw] == '#' for nh, nw in N])))

for h in range(H):

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

H, W = list(map(int, input().split()))
S = [eval(input()) for _ in range(H)]
ans = [[""] * W for _ in range(H)]
N = [(1, 1), (1, 0), (1, -1), (0, 1), (0, -1), (-1, 1), (-1, 0), (-1, -1)]
for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            ans[h][w] = "#"
        else:
            ans[h][w] = str(
                sum(
                    [
                        S[h + nh][w + nw] == "#"
                        for nh, nw in N
                        if 0 <= h + nh < H and 0 <= w + nw < W
                    ]
                )
            )
for h in range(H):
    print(("".join(ans[h])))

H, W = list(map(int, input().split()))
S = ["." * (W + 2)] + ["." + eval(input()) + "." for _ in range(H)] + ["." * (W + 2)]
ans = [[] for _ in range(H)]
N = [(1, 1), (1, 0), (1, -1), (0, 1), (0, -1), (-1, 1), (-1, 0), (-1, -1)]
for h in range(1, H + 1):
    for w in range(1, W + 1):
        if S[h][w] == "#":
            ans[h - 1].append("#")
        else:
            ans[h - 1].append(str(sum([S[h + nh][w + nw] == "#" for nh, nw in N])))
for h in range(H):
    print(("".join(ans[h])))

-S = [eval(input()) for _ in range(H)] -ans = [[""] * W for _ in range(H)] +S = ["." * (W + 2)] + ["." + eval(input()) + "." for _ in range(H)] + ["." * (W + 2)] +ans = [[] for _ in range(H)] -for h in range(H): -    for w in range(W): +for h in range(1, H + 1): +    for w in range(1, W + 1): -            ans[h][w] = "#" +            ans[h - 1].append("#") -            ans[h][w] = str( -                sum( -                    [ -                        S[h + nh][w + nw] == "#" -                        for nh, nw in N -                        if 0 <= h + nh < H and 0 <= w + nw < W -                    ] -                ) -            ) +            ans[h - 1].append(str(sum([S[h + nh][w + nw] == "#" for nh, nw in N])))