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

S=["."]*(W+2)

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

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

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

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

            print("#",end="")

        else:

            print((S[i-1][j-1]+S[i-1][j]+S[i-1][j+1]+S[i][j-1]+S[i][j+1]+S[i+1][j-1]+S[i+1][j]+S[i+1][j+1]).count("#"),end="")

    print()

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

#H×Wのマス目入力の周りに"."を付け加える関数

def pixel_input(H,W,border="."):

    pixel = [[border]*(W+2)] + \

    [[border] + list(input()) + [border] for _ in range(H)] + \

    [[border]*(W+2)]

    return pixel

#マス目型2次元配列を出力する関数

def pixel_print(pixel):

    for i in range(len(pixel)):

        print("".join(pixel[i]))

S=pixel_input(H,W)

T=[["?" for _ in range(W)] for _ in range(H)]



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

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

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

            T[i-1][j-1]="#"

        else:

            T[i-1][j-1]=str((S[i-1][j-1]+S[i-1][j]+S[i-1][j+1]+S[i][j-1]+S[i][j+1]+S[i+1][j-1]+S[i+1][j]+S[i+1][j+1]).count("#"))

pixel_print(T)

H, W = map(int, input().split())
S = ["."] * (W + 2)
S = (
    [["."] * (W + 2)]
    + [list("." + input() + ".") for _ in range(H)]
    + [["."] * (W + 2)]
)
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if S[i][j] == "#":
            print("#", end="")
        else:
            print(
                (
                    S[i - 1][j - 1]
                    + S[i - 1][j]
                    + S[i - 1][j + 1]
                    + S[i][j - 1]
                    + S[i][j + 1]
                    + S[i + 1][j - 1]
                    + S[i + 1][j]
                    + S[i + 1][j + 1]
                ).count("#"),
                end="",
            )
    print()

H, W = map(int, input().split())
# H×Wのマス目入力の周りに"."を付け加える関数
def pixel_input(H, W, border="."):
    pixel = (
        [[border] * (W + 2)]
        + [[border] + list(input()) + [border] for _ in range(H)]
        + [[border] * (W + 2)]
    )
    return pixel


# マス目型2次元配列を出力する関数
def pixel_print(pixel):
    for i in range(len(pixel)):
        print("".join(pixel[i]))


S = pixel_input(H, W)
T = [["?" for _ in range(W)] for _ in range(H)]
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if S[i][j] == "#":
            T[i - 1][j - 1] = "#"
        else:
            T[i - 1][j - 1] = str(
                (
                    S[i - 1][j - 1]
                    + S[i - 1][j]
                    + S[i - 1][j + 1]
                    + S[i][j - 1]
                    + S[i][j + 1]
                    + S[i + 1][j - 1]
                    + S[i + 1][j]
                    + S[i + 1][j + 1]
                ).count("#")
            )
pixel_print(T)

-S = ["."] * (W + 2) -S = ( -    [["."] * (W + 2)] -    + [list("." + input() + ".") for _ in range(H)] -    + [["."] * (W + 2)] -) +# H×Wのマス目入力の周りに"."を付け加える関数 +def pixel_input(H, W, border="."): +    pixel = ( +        [[border] * (W + 2)] +        + [[border] + list(input()) + [border] for _ in range(H)] +        + [[border] * (W + 2)] +    ) +    return pixel + + +# マス目型2次元配列を出力する関数 +def pixel_print(pixel): +    for i in range(len(pixel)): +        print("".join(pixel[i])) + + +S = pixel_input(H, W) +T = [["?" for _ in range(W)] for _ in range(H)] -            print("#", end="") +            T[i - 1][j - 1] = "#" -            print( +            T[i - 1][j - 1] = str( -                ).count("#"), -                end="", +                ).count("#") -    print() +pixel_print(T)