h, w = list(map(int, input().split()))

s = [eval(input()) for _ in range(h)]



t = [[0 for _ in range(w)] for _ in range(h)]

for i in range(h):

    for j in range(w):

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

            bombs = 0

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

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

                    if 0 <= k < h and 0 <= l < w:

                        if s[k][l] == "#":

                            bombs += 1

            else:

                t[i][j] = str(bombs)

        else:

            t[i][j] = "#"

else:

    for i in range(h):

        print(("".join(t[i])))
h, w = list(map(int, input().split()))



wall = ["." * (w + 2)]

s = wall + ["." + eval(input()) + "." for _ in range(h)] + wall



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

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

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

            t = s[i-1][j-1:j+2] + s[i][j-1:j+2] + s[i+1][j-1:j+2]

            s[i] = s[i][:j] + str(t.count("#")) + s[i][j+1:]

    else:

        print((s[i][1:-1]))
h, w = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
t = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            bombs = 0
            for k in range(i - 1, i + 2):
                for l in range(j - 1, j + 2):
                    if 0 <= k < h and 0 <= l < w:
                        if s[k][l] == "#":
                            bombs += 1
            else:
                t[i][j] = str(bombs)
        else:
            t[i][j] = "#"
else:
    for i in range(h):
        print(("".join(t[i])))

h, w = list(map(int, input().split()))
wall = ["." * (w + 2)]
s = wall + ["." + eval(input()) + "." for _ in range(h)] + wall
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s[i][j] == ".":
            t = s[i - 1][j - 1 : j + 2] + s[i][j - 1 : j + 2] + s[i + 1][j - 1 : j + 2]
            s[i] = s[i][:j] + str(t.count("#")) + s[i][j + 1 :]
    else:
        print((s[i][1:-1]))

-s = [eval(input()) for _ in range(h)] -t = [[0 for _ in range(w)] for _ in range(h)] -for i in range(h): -    for j in range(w): +wall = ["." * (w + 2)] +s = wall + ["." + eval(input()) + "." for _ in range(h)] + wall +for i in range(1, h + 1): +    for j in range(1, w + 1): -            bombs = 0 -            for k in range(i - 1, i + 2): -                for l in range(j - 1, j + 2): -                    if 0 <= k < h and 0 <= l < w: -                        if s[k][l] == "#": -                            bombs += 1 -            else: -                t[i][j] = str(bombs) -        else: -            t[i][j] = "#" -else: -    for i in range(h): -        print(("".join(t[i]))) +            t = s[i - 1][j - 1 : j + 2] + s[i][j - 1 : j + 2] + s[i + 1][j - 1 : j + 2] +            s[i] = s[i][:j] + str(t.count("#")) + s[i][j + 1 :] +    else: +        print((s[i][1:-1]))