object Main {
  def main(args: Array[String]): Unit = {
    val factors  = scala.io.StdIn.readLine.split(" ").map{_.toInt}
    var map: Array[String] = Array.empty

    ( 0 until factors( 0 ) ).foreach { i =>
      map ++= scala.io.StdIn.readLine.split( "" ).filter( s => s != "\n" )
    }

    ( 0 until map.length ).foreach{ i =>
      if( map( i ) == "." ) print( countBombsAround( i, map, factors( 0 ), factors( 1 ) ) )
      else print( map( i ) )

      if( i % factors( 1 ) == factors(1) - 1 ) println( "" )
    }
  }

  def countBombsAround( point: Int, map: Array[String], y_size: Int,  x_size: Int): Int = {
    var count = 0

    ( -1 to 1 ).foreach { i =>
      ( -1 to 1 ).foreach { j =>
        val check_y = point/x_size + i
        val check_x = point%x_size + j

        if( !( i == 0 && j == 0 ) && y_size > check_y && check_y >= 0 && x_size > check_x && check_x >= 0) {
          if( map( check_y*x_size + check_x ) == "#" ) count += 1
        }
      }
    }

    return count
  }
}