import sys

def main():

    in1 = input()

    nums, length = in1.split(' ')

    nums= int(nums)

    length = int(length)

    bombs = []



    for i in range(nums):



        bombs.append(input())

    checked = [['']*length for i in range(nums)]

    for i in range(nums):

        for j in range(length):

            if bombs[i][j] == '#':

                checked[i][j] = '#'

            else:

                bombnum = 0

                if i != 0:

                    if j != 0:

                        if bombs[i-1][j-1] == '#':

                            bombnum += 1



                    if j != length -1:

                        if bombs[i-1][j+1] == '#':

                            bombnum += 1



                    if bombs[i-1][j] == '#':

                        bombnum += 1





                if j != 0:

                    if bombs[i][j-1] == '#':

                        bombnum += 1



                if j != length-1:

                    if bombs[i][j+1] == '#':

                        bombnum += 1





                if i != nums-1:

                    if j != 0:

                        if bombs[i+1][j-1] == '#':

                            bombnum += 1



                    if j != length -1:

                        if bombs[i+1][j+1] == '#':

                            bombnum += 1



                    if bombs[i+1][j] == '#':

                        bombnum += 1



                checked[i][j] = bombnum

    for i in checked:

        for j in i:

            print(j, end = '')

        print('')

if __name__ == '__main__':

    main()

def check(b, i, j, x, y):

 if i < 0 or j < 0 or i == x or j == y:

  return 0

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

  return 1

 return 0



bounds = input().split(" ")

x = int(bounds[0])

y = int(bounds[1])

board = [None] * x

for i in range(0, x):

 k = input()

 board[i] = [None] * y

 for j in range(0, y):

  board[i][j] = k[j]



for i in range(0, x):

 for j in range(0, y):

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

   p = 0

   p += check(board, i-1, j-1, x, y)

   p += check(board, i-1, j  , x, y)

   p += check(board, i-1, j+1, x, y)

   p += check(board, i  , j-1, x, y)

   p += check(board, i  , j+1, x, y)

   p += check(board, i+1, j-1, x, y)

   p += check(board, i+1, j  , x, y)

   p += check(board, i+1, j+1, x, y)

   board[i][j] = p

 z = ""

 for j in range(0, y):

  z += str(board[i][j])

 print(z)
import sys


def main():
    in1 = input()
    nums, length = in1.split(" ")
    nums = int(nums)
    length = int(length)
    bombs = []
    for i in range(nums):
        bombs.append(input())
    checked = [[""] * length for i in range(nums)]
    for i in range(nums):
        for j in range(length):
            if bombs[i][j] == "#":
                checked[i][j] = "#"
            else:
                bombnum = 0
                if i != 0:
                    if j != 0:
                        if bombs[i - 1][j - 1] == "#":
                            bombnum += 1
                    if j != length - 1:
                        if bombs[i - 1][j + 1] == "#":
                            bombnum += 1
                    if bombs[i - 1][j] == "#":
                        bombnum += 1
                if j != 0:
                    if bombs[i][j - 1] == "#":
                        bombnum += 1
                if j != length - 1:
                    if bombs[i][j + 1] == "#":
                        bombnum += 1
                if i != nums - 1:
                    if j != 0:
                        if bombs[i + 1][j - 1] == "#":
                            bombnum += 1
                    if j != length - 1:
                        if bombs[i + 1][j + 1] == "#":
                            bombnum += 1
                    if bombs[i + 1][j] == "#":
                        bombnum += 1
                checked[i][j] = bombnum
    for i in checked:
        for j in i:
            print(j, end="")
        print("")


if __name__ == "__main__":
    main()

def check(b, i, j, x, y):
    if i < 0 or j < 0 or i == x or j == y:
        return 0
    if b[i][j] == "#":
        return 1
    return 0


bounds = input().split(" ")
x = int(bounds[0])
y = int(bounds[1])
board = [None] * x
for i in range(0, x):
    k = input()
    board[i] = [None] * y
    for j in range(0, y):
        board[i][j] = k[j]
for i in range(0, x):
    for j in range(0, y):
        if board[i][j] == ".":
            p = 0
            p += check(board, i - 1, j - 1, x, y)
            p += check(board, i - 1, j, x, y)
            p += check(board, i - 1, j + 1, x, y)
            p += check(board, i, j - 1, x, y)
            p += check(board, i, j + 1, x, y)
            p += check(board, i + 1, j - 1, x, y)
            p += check(board, i + 1, j, x, y)
            p += check(board, i + 1, j + 1, x, y)
            board[i][j] = p
    z = ""
    for j in range(0, y):
        z += str(board[i][j])
    print(z)

-import sys +def check(b, i, j, x, y): +    if i < 0 or j < 0 or i == x or j == y: +        return 0 +    if b[i][j] == "#": +        return 1 +    return 0 -def main(): -    in1 = input() -    nums, length = in1.split(" ") -    nums = int(nums) -    length = int(length) -    bombs = [] -    for i in range(nums): -        bombs.append(input()) -    checked = [[""] * length for i in range(nums)] -    for i in range(nums): -        for j in range(length): -            if bombs[i][j] == "#": -                checked[i][j] = "#" -            else: -                bombnum = 0 -                if i != 0: -                    if j != 0: -                        if bombs[i - 1][j - 1] == "#": -                            bombnum += 1 -                    if j != length - 1: -                        if bombs[i - 1][j + 1] == "#": -                            bombnum += 1 -                    if bombs[i - 1][j] == "#": -                        bombnum += 1 -                if j != 0: -                    if bombs[i][j - 1] == "#": -                        bombnum += 1 -                if j != length - 1: -                    if bombs[i][j + 1] == "#": -                        bombnum += 1 -                if i != nums - 1: -                    if j != 0: -                        if bombs[i + 1][j - 1] == "#": -                            bombnum += 1 -                    if j != length - 1: -                        if bombs[i + 1][j + 1] == "#": -                            bombnum += 1 -                    if bombs[i + 1][j] == "#": -                        bombnum += 1 -                checked[i][j] = bombnum -    for i in checked: -        for j in i: -            print(j, end="") -        print("") - - -if __name__ == "__main__": -    main() +bounds = input().split(" ") +x = int(bounds[0]) +y = int(bounds[1]) +board = [None] * x +for i in range(0, x): +    k = input() +    board[i] = [None] * y +    for j in range(0, y): +        board[i][j] = k[j] +for i in range(0, x): +    for j in range(0, y): +        if board[i][j] == ".": +            p = 0 +            p += check(board, i - 1, j - 1, x, y) +            p += check(board, i - 1, j, x, y) +            p += check(board, i - 1, j + 1, x, y) +            p += check(board, i, j - 1, x, y) +            p += check(board, i, j + 1, x, y) +            p += check(board, i + 1, j - 1, x, y) +            p += check(board, i + 1, j, x, y) +            p += check(board, i + 1, j + 1, x, y) +            board[i][j] = p +    z = "" +    for j in range(0, y): +        z += str(board[i][j]) +    print(z)