object Main extends App {
  type Dots = Array[Array[Char]]
  type Point = (Int, Int)

  val Seq(h, w) = scala.io.StdIn.readLine.split(" ").map(_.toInt).toSeq

  var s = ""
  for (_ <- 0 until h) {
    s += scala.io.StdIn.readLine + "\n"
  }

  val dots: Array[Array[Char]] = s.split("\n").map(_.toCharArray)

  for {
    y <- 0 until h
    x <- 0 until w
  } {
    if (dots(y)(x) == '#') print('#')
    else print(surrounds(y, x).flatMap(get(dots, _)).count(_ == '#').toString.charAt(0))
    if (x == w - 1) println()
  }

  def surrounds(h: Int, w: Int): Seq[Point] = (
    for {x <- -1 to 1; y <- -1 to 1} yield (x, y)
    ).filter(_ != (0, 0)).map(t => (h + t._1, w + t._2))

  def get(dots: Dots, point: Point): Option[Char] = try {
    Some(dots(point._1)(point._2))
  } catch {
    case _ => None
  }
}