import numpy as np

h,w=input().split()

h,w=int(h),int(w)

t1=[]

for i in range(h):

    s1=list(input())

    t1.append(s1)



t2=[[0 for i in range(w)] for i in range(h)]

for i in range(h):

    for j in range(w):

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

            for k in range(3):

                for l in range(3):

                    if k==1 and l==1:

                        continue

                    if i+k-1>=0 and j+l-1>=0 and i+k-1<h and j+l-1<w and t1[i+k-1][j+l-1]!="#":

                        t2[i+k-1][j+l-1]+=1

            t2[i][j]="#"

for i in range(h):

    for j in range(w):

        print(t2[i][j],end="")

    print("")

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

s=[list(input()) for i in range(h)]

def count_8(i,j):

    global h,w,s

    cnt=0

    if i-1>=0 and j-1>=0:

        if s[i-1][j-1]=="#":

            cnt+=1

    if i-1>=0 and j+1<=w-1:

        if s[i-1][j+1]=="#":

            cnt+=1

    if i+1<=h-1 and j-1>=0:

        if s[i+1][j-1]=="#":

            cnt+=1

    if i+1<=h-1 and j+1<=w-1:

        if s[i+1][j+1]=="#":

            cnt+=1

    if i-1>=0:

        if s[i-1][j]=="#":

            cnt+=1

    if j-1>=0:

        if s[i][j-1]=="#":

            cnt+=1

    if i+1<=h-1:

        if s[i+1][j]=="#":

            cnt+=1

    if j+1<=w-1:

        if s[i][j+1]=="#":

            cnt+=1

    return str(cnt)

for i in range(h):

    for j in range(w):

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

            print("#",end="")

        else:

            print(count_8(i,j),end="")

    print()

import numpy as np

h, w = input().split()
h, w = int(h), int(w)
t1 = []
for i in range(h):
    s1 = list(input())
    t1.append(s1)
t2 = [[0 for i in range(w)] for i in range(h)]
for i in range(h):
    for j in range(w):
        if t1[i][j] == "#":
            for k in range(3):
                for l in range(3):
                    if k == 1 and l == 1:
                        continue
                    if (
                        i + k - 1 >= 0
                        and j + l - 1 >= 0
                        and i + k - 1 < h
                        and j + l - 1 < w
                        and t1[i + k - 1][j + l - 1] != "#"
                    ):
                        t2[i + k - 1][j + l - 1] += 1
            t2[i][j] = "#"
for i in range(h):
    for j in range(w):
        print(t2[i][j], end="")
    print("")

h, w = map(int, input().split())
s = [list(input()) for i in range(h)]


def count_8(i, j):
    global h, w, s
    cnt = 0
    if i - 1 >= 0 and j - 1 >= 0:
        if s[i - 1][j - 1] == "#":
            cnt += 1
    if i - 1 >= 0 and j + 1 <= w - 1:
        if s[i - 1][j + 1] == "#":
            cnt += 1
    if i + 1 <= h - 1 and j - 1 >= 0:
        if s[i + 1][j - 1] == "#":
            cnt += 1
    if i + 1 <= h - 1 and j + 1 <= w - 1:
        if s[i + 1][j + 1] == "#":
            cnt += 1
    if i - 1 >= 0:
        if s[i - 1][j] == "#":
            cnt += 1
    if j - 1 >= 0:
        if s[i][j - 1] == "#":
            cnt += 1
    if i + 1 <= h - 1:
        if s[i + 1][j] == "#":
            cnt += 1
    if j + 1 <= w - 1:
        if s[i][j + 1] == "#":
            cnt += 1
    return str(cnt)


for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            print("#", end="")
        else:
            print(count_8(i, j), end="")
    print()

-import numpy as np +h, w = map(int, input().split()) +s = [list(input()) for i in range(h)] -h, w = input().split() -h, w = int(h), int(w) -t1 = [] -for i in range(h): -    s1 = list(input()) -    t1.append(s1) -t2 = [[0 for i in range(w)] for i in range(h)] + +def count_8(i, j): +    global h, w, s +    cnt = 0 +    if i - 1 >= 0 and j - 1 >= 0: +        if s[i - 1][j - 1] == "#": +            cnt += 1 +    if i - 1 >= 0 and j + 1 <= w - 1: +        if s[i - 1][j + 1] == "#": +            cnt += 1 +    if i + 1 <= h - 1 and j - 1 >= 0: +        if s[i + 1][j - 1] == "#": +            cnt += 1 +    if i + 1 <= h - 1 and j + 1 <= w - 1: +        if s[i + 1][j + 1] == "#": +            cnt += 1 +    if i - 1 >= 0: +        if s[i - 1][j] == "#": +            cnt += 1 +    if j - 1 >= 0: +        if s[i][j - 1] == "#": +            cnt += 1 +    if i + 1 <= h - 1: +        if s[i + 1][j] == "#": +            cnt += 1 +    if j + 1 <= w - 1: +        if s[i][j + 1] == "#": +            cnt += 1 +    return str(cnt) + + -        if t1[i][j] == "#": -            for k in range(3): -                for l in range(3): -                    if k == 1 and l == 1: -                        continue -                    if ( -                        i + k - 1 >= 0 -                        and j + l - 1 >= 0 -                        and i + k - 1 < h -                        and j + l - 1 < w -                        and t1[i + k - 1][j + l - 1] != "#" -                    ): -                        t2[i + k - 1][j + l - 1] += 1 -            t2[i][j] = "#" -for i in range(h): -    for j in range(w): -        print(t2[i][j], end="") -    print("") +        if s[i][j] == "#": +            print("#", end="") +        else: +            print(count_8(i, j), end="") +    print()