h, w = (int(i) for i in input().split())

s = [[j for j in input()] for i in range(h)]

for i in range(h):

    for j in range(w):

        cnt = 0

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

            continue

        for k in range(-1,2):

            for l in range(-1,2):

                if 0 <= i+k <= h-1 and 0 <= j+l <= w-1 and s[i+k][j+l] == "#":

                    cnt += 1

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



for i in s:

    print(*i,sep="")

def main():

    H, W = (int(i) for i in input().split())

    A = [eval(input()) for i in range(H)]

    dxy = ((-1, 1), (0, 1), (1, 1), (1, 0),

           (1, -1), (0, -1), (-1, -1), (-1, 0))

    c = [["0"]*W for h in range(H)]

    for h in range(H):

        for w in range(W):

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

                c[h][w] = "#"

            else:

                cur = 0

                for dx, dy in dxy:

                    if not(0 <= h + dy < H and 0 <= w + dx < W):

                        continue

                    if A[h + dy][w + dx] == "#":

                        cur += 1

                c[h][w] = str(cur)

    for h in range(H):

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





if __name__ == '__main__':

    main()

h, w = (int(i) for i in input().split())
s = [[j for j in input()] for i in range(h)]
for i in range(h):
    for j in range(w):
        cnt = 0
        if s[i][j] == "#":
            continue
        for k in range(-1, 2):
            for l in range(-1, 2):
                if (
                    0 <= i + k <= h - 1
                    and 0 <= j + l <= w - 1
                    and s[i + k][j + l] == "#"
                ):
                    cnt += 1
        s[i][j] = str(cnt)
for i in s:
    print(*i, sep="")

def main():
    H, W = (int(i) for i in input().split())
    A = [eval(input()) for i in range(H)]
    dxy = ((-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0))
    c = [["0"] * W for h in range(H)]
    for h in range(H):
        for w in range(W):
            if A[h][w] == "#":
                c[h][w] = "#"
            else:
                cur = 0
                for dx, dy in dxy:
                    if not (0 <= h + dy < H and 0 <= w + dx < W):
                        continue
                    if A[h + dy][w + dx] == "#":
                        cur += 1
                c[h][w] = str(cur)
    for h in range(H):
        print(("".join(c[h])))


if __name__ == "__main__":
    main()

-h, w = (int(i) for i in input().split()) -s = [[j for j in input()] for i in range(h)] -for i in range(h): -    for j in range(w): -        cnt = 0 -        if s[i][j] == "#": -            continue -        for k in range(-1, 2): -            for l in range(-1, 2): -                if ( -                    0 <= i + k <= h - 1 -                    and 0 <= j + l <= w - 1 -                    and s[i + k][j + l] == "#" -                ): -                    cnt += 1 -        s[i][j] = str(cnt) -for i in s: -    print(*i, sep="") +def main(): +    H, W = (int(i) for i in input().split()) +    A = [eval(input()) for i in range(H)] +    dxy = ((-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0)) +    c = [["0"] * W for h in range(H)] +    for h in range(H): +        for w in range(W): +            if A[h][w] == "#": +                c[h][w] = "#" +            else: +                cur = 0 +                for dx, dy in dxy: +                    if not (0 <= h + dy < H and 0 <= w + dx < W): +                        continue +                    if A[h + dy][w + dx] == "#": +                        cur += 1 +                c[h][w] = str(cur) +    for h in range(H): +        print(("".join(c[h]))) + + +if __name__ == "__main__": +    main()