import sys

from collections import Counter



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

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



def check_mine(v):

    if v == '#':

        return 1

    else:

        return 0



for i in range(h):

    for j in range(w):

        if s_list[i][j] == '.':

            tmp = 0

            if i != 0:

                if j != 0:

                    tmp += check_mine(s_list[i-1][j-1])

                if j != w-1:

                    tmp += check_mine(s_list[i-1][j+1])

                tmp += check_mine(s_list[i-1][j])



            if i != h-1:

                if j != 0:

                    tmp += check_mine(s_list[i+1][j-1])

                if j != w-1:

                    tmp += check_mine(s_list[i+1][j+1])

                tmp += check_mine(s_list[i+1][j])



            if j != 0:

                tmp += check_mine(s_list[i][j-1])



            if j != w-1:

                tmp += check_mine(s_list[i][j+1])

            

            s_list[i][j] = str(tmp)



for i in s_list:

    print((''.join(i)))

import sys

from collections import Counter



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

s_list = [list('.' * (w + 2))]

s_list.extend([list('.' + eval(input()) + '.') for i in range(h)])

s_list.append(list('.' * (w + 2)))



def check_mine(v):

    if v == '#':

        return 1

    else:

        return 0



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

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

        if s_list[i][j] == '.':

            cnt = 0

            cnt += s_list[i-1][j-1:j+2].count('#')

            cnt += s_list[i][j-1:j+2].count('#')

            cnt += s_list[i+1][j-1:j+2].count('#')

            s_list[i][j] = str(cnt)



for i in s_list[1:-1]:

    print((''.join(i[1:-1])))
import sys
from collections import Counter

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


def check_mine(v):
    if v == "#":
        return 1
    else:
        return 0


for i in range(h):
    for j in range(w):
        if s_list[i][j] == ".":
            tmp = 0
            if i != 0:
                if j != 0:
                    tmp += check_mine(s_list[i - 1][j - 1])
                if j != w - 1:
                    tmp += check_mine(s_list[i - 1][j + 1])
                tmp += check_mine(s_list[i - 1][j])
            if i != h - 1:
                if j != 0:
                    tmp += check_mine(s_list[i + 1][j - 1])
                if j != w - 1:
                    tmp += check_mine(s_list[i + 1][j + 1])
                tmp += check_mine(s_list[i + 1][j])
            if j != 0:
                tmp += check_mine(s_list[i][j - 1])
            if j != w - 1:
                tmp += check_mine(s_list[i][j + 1])
            s_list[i][j] = str(tmp)
for i in s_list:
    print(("".join(i)))

import sys
from collections import Counter

h, w = list(map(int, input().split()))
s_list = [list("." * (w + 2))]
s_list.extend([list("." + eval(input()) + ".") for i in range(h)])
s_list.append(list("." * (w + 2)))


def check_mine(v):
    if v == "#":
        return 1
    else:
        return 0


for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s_list[i][j] == ".":
            cnt = 0
            cnt += s_list[i - 1][j - 1 : j + 2].count("#")
            cnt += s_list[i][j - 1 : j + 2].count("#")
            cnt += s_list[i + 1][j - 1 : j + 2].count("#")
            s_list[i][j] = str(cnt)
for i in s_list[1:-1]:
    print(("".join(i[1:-1])))

-s_list = [list(eval(input())) for i in range(h)] +s_list = [list("." * (w + 2))] +s_list.extend([list("." + eval(input()) + ".") for i in range(h)]) +s_list.append(list("." * (w + 2))) -for i in range(h): -    for j in range(w): +for i in range(1, h + 1): +    for j in range(1, w + 1): -            tmp = 0 -            if i != 0: -                if j != 0: -                    tmp += check_mine(s_list[i - 1][j - 1]) -                if j != w - 1: -                    tmp += check_mine(s_list[i - 1][j + 1]) -                tmp += check_mine(s_list[i - 1][j]) -            if i != h - 1: -                if j != 0: -                    tmp += check_mine(s_list[i + 1][j - 1]) -                if j != w - 1: -                    tmp += check_mine(s_list[i + 1][j + 1]) -                tmp += check_mine(s_list[i + 1][j]) -            if j != 0: -                tmp += check_mine(s_list[i][j - 1]) -            if j != w - 1: -                tmp += check_mine(s_list[i][j + 1]) -            s_list[i][j] = str(tmp) -for i in s_list: -    print(("".join(i))) +            cnt = 0 +            cnt += s_list[i - 1][j - 1 : j + 2].count("#") +            cnt += s_list[i][j - 1 : j + 2].count("#") +            cnt += s_list[i + 1][j - 1 : j + 2].count("#") +            s_list[i][j] = str(cnt) +for i in s_list[1:-1]: +    print(("".join(i[1:-1])))