from sys import stdin,setrecursionlimit

setrecursionlimit(10 ** 7)



h,w = list(map(int,stdin.readline().rstrip().split()))

s = [stdin.readline().rstrip() for _ in range(h)]



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



x = [-1,0,1]

y = [-1,0,1]



for i in range(h):

    for j in range(w):

        count = 0

        for xx in x:

            for yy in y:

                if xx == 0 and yy == 0:

                    continue

                if j+xx < 0 or j+xx > w-1:

                    continue

                if i+yy < 0 or i+yy > h-1:

                    continue

                if s[i+yy][j+xx] == "#":

                    count += 1

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

            li[i][j] = "#"

        else:li[i][j] = str(count)



for i in li:

    print(("".join(i)))
h,w = list(map(int,input().split()))



s = ["."*(w+2)]

for _ in range(h):

    s.append("."+eval(input())+".")

s.append("."*(w+2))



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



h += 2

w += 2



for i in range(1,h-1):

    for j in range(1,w-1):

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

            li[i-1][j-1] = "#"

            continue

        point = 0

        x = [-1,0,1]

        y = [-1,0,1]

        for nx in x:

            for ny in y:

                if nx == 0 and ny == 0:

                    continue

                if s[i+nx][j+ny] == "#":

                    point += 1

        li[i-1][j-1] = point



for i in li:

    print((''.join(map(str,i))))
from sys import stdin, setrecursionlimit

setrecursionlimit(10**7)
h, w = list(map(int, stdin.readline().rstrip().split()))
s = [stdin.readline().rstrip() for _ in range(h)]
li = [[0 for i in range(w)] for j in range(h)]
x = [-1, 0, 1]
y = [-1, 0, 1]
for i in range(h):
    for j in range(w):
        count = 0
        for xx in x:
            for yy in y:
                if xx == 0 and yy == 0:
                    continue
                if j + xx < 0 or j + xx > w - 1:
                    continue
                if i + yy < 0 or i + yy > h - 1:
                    continue
                if s[i + yy][j + xx] == "#":
                    count += 1
        if s[i][j] == "#":
            li[i][j] = "#"
        else:
            li[i][j] = str(count)
for i in li:
    print(("".join(i)))

h, w = list(map(int, input().split()))
s = ["." * (w + 2)]
for _ in range(h):
    s.append("." + eval(input()) + ".")
s.append("." * (w + 2))
li = [[0 for j in range(w)] for i in range(h)]
h += 2
w += 2
for i in range(1, h - 1):
    for j in range(1, w - 1):
        if s[i][j] == "#":
            li[i - 1][j - 1] = "#"
            continue
        point = 0
        x = [-1, 0, 1]
        y = [-1, 0, 1]
        for nx in x:
            for ny in y:
                if nx == 0 and ny == 0:
                    continue
                if s[i + nx][j + ny] == "#":
                    point += 1
        li[i - 1][j - 1] = point
for i in li:
    print(("".join(map(str, i))))

-from sys import stdin, setrecursionlimit - -setrecursionlimit(10**7) -h, w = list(map(int, stdin.readline().rstrip().split())) -s = [stdin.readline().rstrip() for _ in range(h)] -li = [[0 for i in range(w)] for j in range(h)] -x = [-1, 0, 1] -y = [-1, 0, 1] -for i in range(h): -    for j in range(w): -        count = 0 -        for xx in x: -            for yy in y: -                if xx == 0 and yy == 0: +h, w = list(map(int, input().split())) +s = ["." * (w + 2)] +for _ in range(h): +    s.append("." + eval(input()) + ".") +s.append("." * (w + 2)) +li = [[0 for j in range(w)] for i in range(h)] +h += 2 +w += 2 +for i in range(1, h - 1): +    for j in range(1, w - 1): +        if s[i][j] == "#": +            li[i - 1][j - 1] = "#" +            continue +        point = 0 +        x = [-1, 0, 1] +        y = [-1, 0, 1] +        for nx in x: +            for ny in y: +                if nx == 0 and ny == 0: -                if j + xx < 0 or j + xx > w - 1: -                    continue -                if i + yy < 0 or i + yy > h - 1: -                    continue -                if s[i + yy][j + xx] == "#": -                    count += 1 -        if s[i][j] == "#": -            li[i][j] = "#" -        else: -            li[i][j] = str(count) +                if s[i + nx][j + ny] == "#": +                    point += 1 +        li[i - 1][j - 1] = point -    print(("".join(i))) +    print(("".join(map(str, i))))