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

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

ans = []

for i in range(h):

    buf = []

    for j in range(w):

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

            cnt = 0

            for r in range(max(0, i - 1), min(h, i + 2)):

                for c in range(max(0, j - 1), min(w, j + 2)):

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

                        cnt += 1

            buf += [cnt]

        else:

            buf += ['#']

    buf = list(map(str, buf))

    ans.append(buf)

for _ in ans:

    print((''.join(_)))
def main():

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

    s = [input() for _ in range(H)]

    ctr = [[0] * W for _ in range(H)]

    for r, row in enumerate(s):

        for c, cell in enumerate(row):

            if cell == '#':

                for dr in (-1, 0, 1):

                    for dc in (-1, 0, 1):

                        if 0 <= r + dr < H and 0 <= c + dc < W and s[r + dr][c + dc] == '.':

                            ctr[r + dr][c + dc] += 1

    for r in range(H):

        for c in range(W):

            print('#' if s[r][c] == '#' else ctr[r][c], end='')

        print()





if __name__ == '__main__':

    main()



# import sys

#

# sys.setrecursionlimit(10 ** 7)

#

# input = sys.stdin.readline

# rstrip()

# int(input())

# map(int, input().split())

h, w = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
ans = []
for i in range(h):
    buf = []
    for j in range(w):
        if s[i][j] == ".":
            cnt = 0
            for r in range(max(0, i - 1), min(h, i + 2)):
                for c in range(max(0, j - 1), min(w, j + 2)):
                    if s[r][c] == "#":
                        cnt += 1
            buf += [cnt]
        else:
            buf += ["#"]
    buf = list(map(str, buf))
    ans.append(buf)
for _ in ans:
    print(("".join(_)))

def main():
    H, W = map(int, input().split())
    s = [input() for _ in range(H)]
    ctr = [[0] * W for _ in range(H)]
    for r, row in enumerate(s):
        for c, cell in enumerate(row):
            if cell == "#":
                for dr in (-1, 0, 1):
                    for dc in (-1, 0, 1):
                        if (
                            0 <= r + dr < H
                            and 0 <= c + dc < W
                            and s[r + dr][c + dc] == "."
                        ):
                            ctr[r + dr][c + dc] += 1
    for r in range(H):
        for c in range(W):
            print("#" if s[r][c] == "#" else ctr[r][c], end="")
        print()


if __name__ == "__main__":
    main()
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

-h, w = list(map(int, input().split())) -s = [eval(input()) for _ in range(h)] -ans = [] -for i in range(h): -    buf = [] -    for j in range(w): -        if s[i][j] == ".": -            cnt = 0 -            for r in range(max(0, i - 1), min(h, i + 2)): -                for c in range(max(0, j - 1), min(w, j + 2)): -                    if s[r][c] == "#": -                        cnt += 1 -            buf += [cnt] -        else: -            buf += ["#"] -    buf = list(map(str, buf)) -    ans.append(buf) -for _ in ans: -    print(("".join(_))) +def main(): +    H, W = map(int, input().split()) +    s = [input() for _ in range(H)] +    ctr = [[0] * W for _ in range(H)] +    for r, row in enumerate(s): +        for c, cell in enumerate(row): +            if cell == "#": +                for dr in (-1, 0, 1): +                    for dc in (-1, 0, 1): +                        if ( +                            0 <= r + dr < H +                            and 0 <= c + dc < W +                            and s[r + dr][c + dc] == "." +                        ): +                            ctr[r + dr][c + dc] += 1 +    for r in range(H): +        for c in range(W): +            print("#" if s[r][c] == "#" else ctr[r][c], end="") +        print() + + +if __name__ == "__main__": +    main() +# import sys +# +# sys.setrecursionlimit(10 ** 7) +# +# input = sys.stdin.readline +# rstrip() +# int(input()) +# map(int, input().split())