def f(i,j):

    cnt = 0

    if j<W-1 and A[i][j+1]=="#":

        cnt += 1

    if j<W-1 and i>=1 and A[i-1][j+1]=="#":

        cnt += 1

    if i>=1 and A[i-1][j]=="#":

        cnt += 1

    if i>=1 and j>=1 and A[i-1][j-1]=="#":

        cnt += 1

    if j>=1 and A[i][j-1]=="#":

        cnt += 1

    if i<H-1 and j>=1 and A[i+1][j-1]=="#":

        cnt += 1

    if i<H-1 and A[i+1][j]=="#":

        cnt += 1

    if i<H-1 and j<W-1 and A[i+1][j+1]=="#":

        cnt += 1

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

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

A = [list(input().strip()) for _ in range(H)]

for i in range(H):

    for j in range(W):

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

            f(i,j)

for i in range(H):

    print(("".join(A[i])))
H,W = list(map(int,input().split()))

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

for i in range(H):

    x=input().strip()

    x = "."+x+"."

    S.append(x)

S.append("."*(W+2))

A = [[0 for _ in range(W+1)] for _ in range(H+1)]

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

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

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

            A[i][j] = "#"

        else:

            cnt = 0

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

                cnt += 1

            if S[i-1][j+1]=="#":

                cnt += 1

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

                cnt += 1

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

                cnt += 1

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

                cnt += 1

            if S[i+1][j-1]=="#":

                cnt += 1

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

                cnt += 1

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

                cnt += 1

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

    print(("".join(A[i][1:W+1])))
def f(i, j):
    cnt = 0
    if j < W - 1 and A[i][j + 1] == "#":
        cnt += 1
    if j < W - 1 and i >= 1 and A[i - 1][j + 1] == "#":
        cnt += 1
    if i >= 1 and A[i - 1][j] == "#":
        cnt += 1
    if i >= 1 and j >= 1 and A[i - 1][j - 1] == "#":
        cnt += 1
    if j >= 1 and A[i][j - 1] == "#":
        cnt += 1
    if i < H - 1 and j >= 1 and A[i + 1][j - 1] == "#":
        cnt += 1
    if i < H - 1 and A[i + 1][j] == "#":
        cnt += 1
    if i < H - 1 and j < W - 1 and A[i + 1][j + 1] == "#":
        cnt += 1
    A[i][j] = str(cnt)


H, W = list(map(int, input().split()))
A = [list(input().strip()) for _ in range(H)]
for i in range(H):
    for j in range(W):
        if A[i][j] == ".":
            f(i, j)
for i in range(H):
    print(("".join(A[i])))

H, W = list(map(int, input().split()))
S = ["." * (W + 2)]
for i in range(H):
    x = input().strip()
    x = "." + x + "."
    S.append(x)
S.append("." * (W + 2))
A = [[0 for _ in range(W + 1)] for _ in range(H + 1)]
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if S[i][j] == "#":
            A[i][j] = "#"
        else:
            cnt = 0
            if S[i][j + 1] == "#":
                cnt += 1
            if S[i - 1][j + 1] == "#":
                cnt += 1
            if S[i - 1][j] == "#":
                cnt += 1
            if S[i - 1][j - 1] == "#":
                cnt += 1
            if S[i][j - 1] == "#":
                cnt += 1
            if S[i + 1][j - 1] == "#":
                cnt += 1
            if S[i + 1][j] == "#":
                cnt += 1
            if S[i + 1][j + 1] == "#":
                cnt += 1
            A[i][j] = str(cnt)
    print(("".join(A[i][1 : W + 1])))

-def f(i, j): -    cnt = 0 -    if j < W - 1 and A[i][j + 1] == "#": -        cnt += 1 -    if j < W - 1 and i >= 1 and A[i - 1][j + 1] == "#": -        cnt += 1 -    if i >= 1 and A[i - 1][j] == "#": -        cnt += 1 -    if i >= 1 and j >= 1 and A[i - 1][j - 1] == "#": -        cnt += 1 -    if j >= 1 and A[i][j - 1] == "#": -        cnt += 1 -    if i < H - 1 and j >= 1 and A[i + 1][j - 1] == "#": -        cnt += 1 -    if i < H - 1 and A[i + 1][j] == "#": -        cnt += 1 -    if i < H - 1 and j < W - 1 and A[i + 1][j + 1] == "#": -        cnt += 1 -    A[i][j] = str(cnt) - - -A = [list(input().strip()) for _ in range(H)] +S = ["." * (W + 2)] -    for j in range(W): -        if A[i][j] == ".": -            f(i, j) -for i in range(H): -    print(("".join(A[i]))) +    x = input().strip() +    x = "." + x + "." +    S.append(x) +S.append("." * (W + 2)) +A = [[0 for _ in range(W + 1)] for _ in range(H + 1)] +for i in range(1, H + 1): +    for j in range(1, W + 1): +        if S[i][j] == "#": +            A[i][j] = "#" +        else: +            cnt = 0 +            if S[i][j + 1] == "#": +                cnt += 1 +            if S[i - 1][j + 1] == "#": +                cnt += 1 +            if S[i - 1][j] == "#": +                cnt += 1 +            if S[i - 1][j - 1] == "#": +                cnt += 1 +            if S[i][j - 1] == "#": +                cnt += 1 +            if S[i + 1][j - 1] == "#": +                cnt += 1 +            if S[i + 1][j] == "#": +                cnt += 1 +            if S[i + 1][j + 1] == "#": +                cnt += 1 +            A[i][j] = str(cnt) +    print(("".join(A[i][1 : W + 1])))