import scala.io.StdIn

object Main extends App {
  val dx = Array(-1, 0, 1, -1, 1, -1, 0, 1)
  val dy = Array(-1, -1, -1, 0, 0, 1, 1, 1)
  val out = new java.io.PrintWriter(System.out)

  val Array(h, w) = StdIn.readLine.split(" ").map(_.toInt)
  val map = Iterator.continually(StdIn.readLine)
    .take(h)
    .toArray

  val res = for {
    i <- 0 until h
    j <- 0 until w
  } yield {
    if(map(i)(j) == '#') "#"
    else {
      (0 until 8)./:(0)((a,e) => {
        val y = i + dy(e)
        val x = j + dx(e)
        if(0 <= x && x < w && 0 <= y && y < h) a + ( if(map(y)(x) == '#') 1 else 0 )
        else a
      })
    }
  }
  // ans.transpose.toArray
  val ite = res.grouped(w)
  ite.foreach(ans => out.println(ans.mkString("")))
  out.flush
}