object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datH, datW) = readLine.split(" ").map(_.toInt)
    val board = for(i <- 1 to datH) yield readLine.split("").filterNot(_ == "").map(_(0))
    val board2 = board.map( Array('*') ++ _ ++ Array('*') )
    // board2.foreach(a=> println("DEBUG: " + " " + a.length + " " + a.mkString))

    def searchMine(x: Int, y: Int): Char = {
      if( board2(y)(x) == '#' ) '#'
      else if( board2(y)(x) == '*' ) '*'
      else {
        val upperline = if (y - 1 < 0) 0 else
          (if (board2(y - 1)(x - 1) == '#') 1 else 0) +
          (if (board2(y - 1)(x    ) == '#') 1 else 0) +
          (if (board2(y - 1)(x + 1) == '#') 1 else 0)
        val centerline =
          (if (board2(y    )(x - 1) == '#') 1 else 0) +
          (if (board2(y    )(x + 1) == '#') 1 else 0)
        val lowerline = if (y + 1 >= datH) 0 else
          (if (board2(y + 1)(x - 1) == '#') 1 else 0) +
          (if (board2(y + 1)(x    ) == '#') 1 else 0) +
          (if (board2(y + 1)(x + 1) == '#') 1 else 0)
        // println(s"DEBUG: $x $y $upperline $centerline $lowerline")
        (upperline + centerline + lowerline + '0').toChar
      }
    }
    val board3 = for(y <- 0 until datH ; x <- 1 to datW) yield searchMine(x, y)
    val board4 = board3.grouped(datW)
    board4.foreach (a => println( a.mkString ))
  }
}
