import itertools



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

S = []

ans = []

for _ in range(H):

    S.append(list(eval(input())))

    ans.append(['#' for i in range(W)])



op =[]

for i in itertools.product([-1, 0, 1], repeat=2):

    op.append(i)





for i, s1 in enumerate(S):

    for j, s2 in enumerate(s1):

        if(s2 == '.'):

            counter = 0

            for o in op:

                if(i == 0 and o[0] == -1):

                    continue

                elif(i == H-1 and o[0] == 1):

                    continue

                elif(j == 0 and o[1] == -1):

                    continue

                elif(j == W-1 and o[1] == 1):

                    continue

                else:

                    if(S[i + o[0]][j + o[1]] == "#"):

                        counter += 1

            ans[i][j] = str(counter)



for a in ans:

    print((''.join(a)))


def myAnswer(H:int,W:int,S:list) -> None:

   ans = [["#" for _ in range(W+2)]]

   index = []

   for i,s in enumerate(S):

      tmp = ["#"]

      for j,b in enumerate(s):

         if(b == "."):

            tmp.append(0)

         else:

            index.append([i+1,j+1])

            tmp.append(b)

      tmp.append("#")

      ans.append(tmp)

   ans.append(["#" for i in range(W+2)])

   for i,j in index:

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

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

            if(ans[n][m]!="#"):

               ans[n][m] +=1

   ans.pop(0)

   ans.pop()

   for a in ans:

      a.pop(0)

      a.pop(-1)

      string = ""

      for s in a:

         string += str(s)

      print(string)

      

def main():

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

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

   myAnswer(H,W,S[:])

if __name__ == '__main__':

   main()
import itertools

H, W = list(map(int, input().split()))
S = []
ans = []
for _ in range(H):
    S.append(list(eval(input())))
    ans.append(["#" for i in range(W)])
op = []
for i in itertools.product([-1, 0, 1], repeat=2):
    op.append(i)
for i, s1 in enumerate(S):
    for j, s2 in enumerate(s1):
        if s2 == ".":
            counter = 0
            for o in op:
                if i == 0 and o[0] == -1:
                    continue
                elif i == H - 1 and o[0] == 1:
                    continue
                elif j == 0 and o[1] == -1:
                    continue
                elif j == W - 1 and o[1] == 1:
                    continue
                else:
                    if S[i + o[0]][j + o[1]] == "#":
                        counter += 1
            ans[i][j] = str(counter)
for a in ans:
    print(("".join(a)))

def myAnswer(H: int, W: int, S: list) -> None:
    ans = [["#" for _ in range(W + 2)]]
    index = []
    for i, s in enumerate(S):
        tmp = ["#"]
        for j, b in enumerate(s):
            if b == ".":
                tmp.append(0)
            else:
                index.append([i + 1, j + 1])
                tmp.append(b)
        tmp.append("#")
        ans.append(tmp)
    ans.append(["#" for i in range(W + 2)])
    for i, j in index:
        for n in range(i - 1, i + 2, 1):
            for m in range(j - 1, j + 2, 1):
                if ans[n][m] != "#":
                    ans[n][m] += 1
    ans.pop(0)
    ans.pop()
    for a in ans:
        a.pop(0)
        a.pop(-1)
        string = ""
        for s in a:
            string += str(s)
        print(string)


def main():
    H, W = list(map(int, input().split()))
    S = [list(eval(input())) for _ in range(H)]
    myAnswer(H, W, S[:])


if __name__ == "__main__":
    main()

-import itertools +def myAnswer(H: int, W: int, S: list) -> None: +    ans = [["#" for _ in range(W + 2)]] +    index = [] +    for i, s in enumerate(S): +        tmp = ["#"] +        for j, b in enumerate(s): +            if b == ".": +                tmp.append(0) +            else: +                index.append([i + 1, j + 1]) +                tmp.append(b) +        tmp.append("#") +        ans.append(tmp) +    ans.append(["#" for i in range(W + 2)]) +    for i, j in index: +        for n in range(i - 1, i + 2, 1): +            for m in range(j - 1, j + 2, 1): +                if ans[n][m] != "#": +                    ans[n][m] += 1 +    ans.pop(0) +    ans.pop() +    for a in ans: +        a.pop(0) +        a.pop(-1) +        string = "" +        for s in a: +            string += str(s) +        print(string) -H, W = list(map(int, input().split())) -S = [] -ans = [] -for _ in range(H): -    S.append(list(eval(input()))) -    ans.append(["#" for i in range(W)]) -op = [] -for i in itertools.product([-1, 0, 1], repeat=2): -    op.append(i) -for i, s1 in enumerate(S): -    for j, s2 in enumerate(s1): -        if s2 == ".": -            counter = 0 -            for o in op: -                if i == 0 and o[0] == -1: -                    continue -                elif i == H - 1 and o[0] == 1: -                    continue -                elif j == 0 and o[1] == -1: -                    continue -                elif j == W - 1 and o[1] == 1: -                    continue -                else: -                    if S[i + o[0]][j + o[1]] == "#": -                        counter += 1 -            ans[i][j] = str(counter) -for a in ans: -    print(("".join(a))) + +def main(): +    H, W = list(map(int, input().split())) +    S = [list(eval(input())) for _ in range(H)] +    myAnswer(H, W, S[:]) + + +if __name__ == "__main__": +    main()