def count_bombs(S, h, w):

    count = 0

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

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

            if i < 0 or j < 0 or i >= len(S) or j >= len(S[0]):

                continue

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

                count += 1

    return count





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

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

for h in range(H):

    for w in range(W):

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

            print("#", end="")

            continue

        print(count_bombs(S, h, w), end="")

    print()

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

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

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

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

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

            continue

        count = 0

        for dh in range(-1, 2):

            for dw in range(-1, 2):

                if S[h + dh][w + dw] == "#":

                    count += 1

        S[h][w] = str(count)

    print(("".join(S[h][1:W+1])))

def count_bombs(S, h, w):
    count = 0
    for i in range(h - 1, h + 2):
        for j in range(w - 1, w + 2):
            if i < 0 or j < 0 or i >= len(S) or j >= len(S[0]):
                continue
            if S[i][j] == "#":
                count += 1
    return count


H, W = map(int, input().split())
S = [input() for _ in range(H)]
for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            print("#", end="")
            continue
        print(count_bombs(S, h, w), end="")
    print()

H, W = list(map(int, input().split()))
S = (
    [["."] * (W + 2)]
    + [["."] + list(eval(input())) + ["."] for _ in range(H)]
    + [["."] * (W + 2)]
)
for h in range(1, H + 1):
    for w in range(1, W + 1):
        if S[h][w] == "#":
            continue
        count = 0
        for dh in range(-1, 2):
            for dw in range(-1, 2):
                if S[h + dh][w + dw] == "#":
                    count += 1
        S[h][w] = str(count)
    print(("".join(S[h][1 : W + 1])))

-def count_bombs(S, h, w): -    count = 0 -    for i in range(h - 1, h + 2): -        for j in range(w - 1, w + 2): -            if i < 0 or j < 0 or i >= len(S) or j >= len(S[0]): -                continue -            if S[i][j] == "#": -                count += 1 -    return count - - -H, W = map(int, input().split()) -S = [input() for _ in range(H)] -for h in range(H): -    for w in range(W): +H, W = list(map(int, input().split())) +S = ( +    [["."] * (W + 2)] +    + [["."] + list(eval(input())) + ["."] for _ in range(H)] +    + [["."] * (W + 2)] +) +for h in range(1, H + 1): +    for w in range(1, W + 1): -            print("#", end="") -        print(count_bombs(S, h, w), end="") -    print() +        count = 0 +        for dh in range(-1, 2): +            for dw in range(-1, 2): +                if S[h + dh][w + dw] == "#": +                    count += 1 +        S[h][w] = str(count) +    print(("".join(S[h][1 : W + 1])))