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

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

for r in range(h):

    l = ''

    for c in range(w):

        if S[r][c] == '#':

            l += '#'

        else:

            l += str(sum([x[max(0,c-1):min(c+2,w)].count('#') for x in S[max(0,r-1):min(r+2,h)]]))

    print(l)
h,w = map(int, input().split())

S = ['.' + input() + '.' for _ in range(h)]

S.insert(0,'.'*(w+2))

S.append('.'*(w+2))



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

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

        if S[r][c] == '#':

            print('#', end='')

            continue

        else:

            count = 0

            count += S[r-1][c-1:c+2].count('#')

            count += S[r][c-1:c+2].count('#')

            count += S[r+1][c-1:c+2].count('#')

            print(count, end='')

    print()

h, w = list(map(int, input().split()))
S = [eval(input()) for _ in range(h)]
for r in range(h):
    l = ""
    for c in range(w):
        if S[r][c] == "#":
            l += "#"
        else:
            l += str(
                sum(
                    [
                        x[max(0, c - 1) : min(c + 2, w)].count("#")
                        for x in S[max(0, r - 1) : min(r + 2, h)]
                    ]
                )
            )
    print(l)

h, w = map(int, input().split())
S = ["." + input() + "." for _ in range(h)]
S.insert(0, "." * (w + 2))
S.append("." * (w + 2))
for r in range(1, h + 1):
    for c in range(1, w + 1):
        if S[r][c] == "#":
            print("#", end="")
            continue
        else:
            count = 0
            count += S[r - 1][c - 1 : c + 2].count("#")
            count += S[r][c - 1 : c + 2].count("#")
            count += S[r + 1][c - 1 : c + 2].count("#")
            print(count, end="")
    print()

-h, w = list(map(int, input().split())) -S = [eval(input()) for _ in range(h)] -for r in range(h): -    l = "" -    for c in range(w): +h, w = map(int, input().split()) +S = ["." + input() + "." for _ in range(h)] +S.insert(0, "." * (w + 2)) +S.append("." * (w + 2)) +for r in range(1, h + 1): +    for c in range(1, w + 1): -            l += "#" +            print("#", end="") +            continue -            l += str( -                sum( -                    [ -                        x[max(0, c - 1) : min(c + 2, w)].count("#") -                        for x in S[max(0, r - 1) : min(r + 2, h)] -                    ] -                ) -            ) -    print(l) +            count = 0 +            count += S[r - 1][c - 1 : c + 2].count("#") +            count += S[r][c - 1 : c + 2].count("#") +            count += S[r + 1][c - 1 : c + 2].count("#") +            print(count, end="") +    print()