object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val H, W = sc.nextInt()
  val squares = Array.fill(H)(sc.next().toCharArray)
  val rounds = for (x <- -1 to 1; y <- -1 to 1 if !(x == 0 && y == 0)) yield x -> y
  for (i <- 0 until H; j <- 0 until W if squares(i)(j) != '#') {
    val x = rounds.count { case (x, y) =>
      if (0 <= i + x && i + x < W && 0 <= j + y && j + y < H) 
        squares(i + x)(j + y) == '#' 
      else false
    }
    squares(i)(j) = (x + '0').toChar
  }
  squares.foreach(line => println(line.mkString))
}
