global h, w, dat

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

dat = []

for i in range(h):

    dat.append(input())

for y in range(h):

    for x in range(w):

        c = 0

        if dat[y][x] == "#":

            print("#", end="")

            continue



        if 0 < y:

            if dat[y - 1][x] == "#":  # 2

                c += 1

            if 0 < x:

                if dat[y - 1][x - 1] == "#":  # 1

                    c += 1

            if w - 1 > x:

                if dat[y - 1][x + 1] == "#":  # 3

                    c += 1

        if 0 < x:

            if dat[y][x - 1] == "#":  # 4

                c += 1

            if y < h - 1:

                if dat[y + 1][x - 1] == "#":  # 7

                    c += 1



        if x < w - 1:

            if dat[y][x + 1] == "#":  # 6

                c += 1

            if y < h - 1:

                if dat[y + 1][x + 1] == "#":  # 9

                    c += 1



        if y < h - 1:

            if dat[y + 1][x] == "#":  # 8

                c += 1

        print(c, end="")

    print("")

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

maze = []

for _ in range(h):

    maze.append(list(eval(input())))

dx = [-1, 0, 1, -1, 1, -1, 0, 1]

dy = [-1, -1, -1, 0, 0, 1, 1, 1]

for hh in range(h):

    for ww in range(w):

        if maze[hh][ww] == "#":

            continue

        cnt = 0

        for di in range(len(dx)):

            ny = hh + dy[di]

            nx = ww + dx[di]

            if ny < 0 or ny > h-1:

                continue

            if nx < 0 or nx > w-1:

                continue

            if maze[ny][nx] == "#":

                cnt += 1

        maze[hh][ww] = str(cnt)

for i in range(h):

    print(("".join(maze[i])))

global h, w, dat
h, w = map(int, input().split())
dat = []
for i in range(h):
    dat.append(input())
for y in range(h):
    for x in range(w):
        c = 0
        if dat[y][x] == "#":
            print("#", end="")
            continue
        if 0 < y:
            if dat[y - 1][x] == "#":  # 2
                c += 1
            if 0 < x:
                if dat[y - 1][x - 1] == "#":  # 1
                    c += 1
            if w - 1 > x:
                if dat[y - 1][x + 1] == "#":  # 3
                    c += 1
        if 0 < x:
            if dat[y][x - 1] == "#":  # 4
                c += 1
            if y < h - 1:
                if dat[y + 1][x - 1] == "#":  # 7
                    c += 1
        if x < w - 1:
            if dat[y][x + 1] == "#":  # 6
                c += 1
            if y < h - 1:
                if dat[y + 1][x + 1] == "#":  # 9
                    c += 1
        if y < h - 1:
            if dat[y + 1][x] == "#":  # 8
                c += 1
        print(c, end="")
    print("")

h, w = list(map(int, input().split()))
maze = []
for _ in range(h):
    maze.append(list(eval(input())))
dx = [-1, 0, 1, -1, 1, -1, 0, 1]
dy = [-1, -1, -1, 0, 0, 1, 1, 1]
for hh in range(h):
    for ww in range(w):
        if maze[hh][ww] == "#":
            continue
        cnt = 0
        for di in range(len(dx)):
            ny = hh + dy[di]
            nx = ww + dx[di]
            if ny < 0 or ny > h - 1:
                continue
            if nx < 0 or nx > w - 1:
                continue
            if maze[ny][nx] == "#":
                cnt += 1
        maze[hh][ww] = str(cnt)
for i in range(h):
    print(("".join(maze[i])))

-global h, w, dat -h, w = map(int, input().split()) -dat = [] +h, w = list(map(int, input().split())) +maze = [] +for _ in range(h): +    maze.append(list(eval(input()))) +dx = [-1, 0, 1, -1, 1, -1, 0, 1] +dy = [-1, -1, -1, 0, 0, 1, 1, 1] +for hh in range(h): +    for ww in range(w): +        if maze[hh][ww] == "#": +            continue +        cnt = 0 +        for di in range(len(dx)): +            ny = hh + dy[di] +            nx = ww + dx[di] +            if ny < 0 or ny > h - 1: +                continue +            if nx < 0 or nx > w - 1: +                continue +            if maze[ny][nx] == "#": +                cnt += 1 +        maze[hh][ww] = str(cnt) -    dat.append(input()) -for y in range(h): -    for x in range(w): -        c = 0 -        if dat[y][x] == "#": -            print("#", end="") -            continue -        if 0 < y: -            if dat[y - 1][x] == "#":  # 2 -                c += 1 -            if 0 < x: -                if dat[y - 1][x - 1] == "#":  # 1 -                    c += 1 -            if w - 1 > x: -                if dat[y - 1][x + 1] == "#":  # 3 -                    c += 1 -        if 0 < x: -            if dat[y][x - 1] == "#":  # 4 -                c += 1 -            if y < h - 1: -                if dat[y + 1][x - 1] == "#":  # 7 -                    c += 1 -        if x < w - 1: -            if dat[y][x + 1] == "#":  # 6 -                c += 1 -            if y < h - 1: -                if dat[y + 1][x + 1] == "#":  # 9 -                    c += 1 -        if y < h - 1: -            if dat[y + 1][x] == "#":  # 8 -                c += 1 -        print(c, end="") -    print("") +    print(("".join(maze[i])))