You are given an H × W grid.   The squares in the grid are described by H strings, S_1,...,S_H.   The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).   `.` stands for an empty square, and `#` stands for a square containing a bomb.  Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.   (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)   He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.  Print the strings after the process.
def check_current_posi(s_i_list, h, w):
  _height = len(s_i_list)
  _width = len(s_i_list[0])
  if h == -1 or w == -1 or h >= _height or w >= _width:
    return False

  else:
    if s_i_list[h][w] == "#":
      # bomb
      return True

    else:
      # not bomb
      return False


def check_around_bomb_num(s_i_list, h, w):

  check_posi_h = h - 1
  check_posi_w = w - 1

  bomb_counter = 0

  for i in range(3):

    for j in range(3):

      if check_current_posi(s_i_list, check_posi_h, check_posi_w):
        bomb_counter += 1

      check_posi_w += 1

    check_posi_h += 1
    check_posi_w = w - 1
  
  return bomb_counter
      

# _input = [6, 6]
_input = list(map(int, input().split(" ")))

height = _input[0]
width = _input[1]

s_i_list = []

for i in range(height):
  _input_row = list(input())
  s_i_list.append(_input_row)

# s_i_list = [['#', '#', '#', '#', '#', '.'], ['#', '.', '#', '.', '#', '#'], ['#', '#', '#', '#', '.', '#'], ['.', '#', '.', '.', '#', '.'], ['#', '.', '#', '#', '.', '.'], ['#', '.', '#', '.', '.', '.']]

for row in range(height):
  for column in range(width):
    if s_i_list[row][column] == "#":
      continue

    s_i_list[row][column] = check_around_bomb_num(s_i_list, row, column)


print(s_i_list)

def check_current_posi(s_i_list, h, w):
  _height = len(s_i_list)
  _width = len(s_i_list[0])
  if h == -1 or w == -1 or h >= _height or w >= _width:
    return False

  else:
    if s_i_list[h][w] == "#":
      # bomb
      return True

    else:
      # not bomb
      return False


def check_around_bomb_num(s_i_list, h, w):

  check_posi_h = h - 1
  check_posi_w = w - 1

  bomb_counter = 0

  for i in range(3):

    for j in range(3):

      if check_current_posi(s_i_list, check_posi_h, check_posi_w):
        bomb_counter += 1

      check_posi_w += 1

    check_posi_h += 1
    check_posi_w = w - 1
  
  return bomb_counter
      

# _input = [6, 6]
_input = list(map(int, input().split(" ")))

height = _input[0]
width = _input[1]

s_i_list = []

for i in range(height):
  _input_row = list(input())
  s_i_list.append(_input_row)

# s_i_list = [['#', '#', '#', '#', '#', '.'], ['#', '.', '#', '.', '#', '#'], ['#', '#', '#', '#', '.', '#'], ['.', '#', '.', '.', '#', '.'], ['#', '.', '#', '#', '.', '.'], ['#', '.', '#', '.', '.', '.']]

for row in range(height):
  for column in range(width):
    if s_i_list[row][column] == "#":
      continue

    s_i_list[row][column] = check_around_bomb_num(s_i_list, row, column)

for row in s_i_list:
  output_row = "".join(list(map(str,row)))
  print(output_row)
