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

S=[]

for i in range(H):

     S.append(input())

for i in range(H):

    for j in range(W):

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

            print("#",end="")

        else:

            rec = 0

            for d in [(1,0),(1,1),(0,1),(-1,1),(-1,0),(-1,-1),(0,-1),(1,-1)]:

                nx,ny = i+d[0],j+d[1]

                if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == "#":

                    rec += 1

            print(rec,end="")

            

    print()

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

S = []

for i in range(H):

    S.append(eval(input()))

for i in range(H):

    for j in range(W):

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

            S[i] = S[i].replace(".", "0", 1)

            rec = 0

            for d in [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]:

                nx, ny = i + d[0], j + d[1]

                if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == "#":

                    rec += 1

            if rec > 0:

                S[i]=S[i][::-1]

                S[i] = S[i].replace("0", str(rec), 1)

                S[i] = S[i][::-1]









for i in range(H):

    print((S[i]))
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(input())
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            print("#", end="")
        else:
            rec = 0
            for d in [
                (1, 0),
                (1, 1),
                (0, 1),
                (-1, 1),
                (-1, 0),
                (-1, -1),
                (0, -1),
                (1, -1),
            ]:
                nx, ny = i + d[0], j + d[1]
                if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == "#":
                    rec += 1
            print(rec, end="")
    print()

H, W = list(map(int, input().split()))
S = []
for i in range(H):
    S.append(eval(input()))
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            S[i] = S[i].replace(".", "0", 1)
            rec = 0
            for d in [
                (1, 0),
                (1, 1),
                (0, 1),
                (-1, 1),
                (-1, 0),
                (-1, -1),
                (0, -1),
                (1, -1),
            ]:
                nx, ny = i + d[0], j + d[1]
                if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == "#":
                    rec += 1
            if rec > 0:
                S[i] = S[i][::-1]
                S[i] = S[i].replace("0", str(rec), 1)
                S[i] = S[i][::-1]
for i in range(H):
    print((S[i]))

-H, W = map(int, input().split()) +H, W = list(map(int, input().split())) -    S.append(input()) +    S.append(eval(input())) -        if S[i][j] == "#": -            print("#", end="") -        else: +        if S[i][j] == ".": +            S[i] = S[i].replace(".", "0", 1) -            print(rec, end="") -    print() +            if rec > 0: +                S[i] = S[i][::-1] +                S[i] = S[i].replace("0", str(rec), 1) +                S[i] = S[i][::-1] +for i in range(H): +    print((S[i]))