object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val Array(h, w) = sc.nextLine.split(" ").map(_.toInt)
  val seqs = Seq.fill(h)(sc.nextLine.split("").toSeq.filter(_.nonEmpty).zipWithIndex).zipWithIndex
  
  def findOpt[T](index: Int, seq: Seq[(T, Int)]): Option[T] = {
    import scala.util.Try
    Try(seq.map{case (t, index) => t}.apply(index)).toOption
  }
  
  val results = seqs.map{ case (seq, seqIndex) =>
    val preSeq = findOpt(seqIndex - 1, seqs)
    val curSeq = findOpt(seqIndex, seqs)
    val nextSeq = findOpt(seqIndex + 1, seqs)

    seq.map { case (e, eIndex) =>
      if (e == "#" ) "#"
      else Seq(preSeq.flatMap(findOpt(eIndex - 1, _)),
              preSeq.flatMap(findOpt(eIndex, _)),
              preSeq.flatMap(findOpt(eIndex + 1, _)),
              curSeq.flatMap(findOpt(eIndex - 1, _)),
              curSeq.flatMap(findOpt(eIndex + 1, _)),
              nextSeq.flatMap(findOpt(eIndex - 1, _)),
              nextSeq.flatMap(findOpt(eIndex, _)),
              nextSeq.flatMap(findOpt(eIndex + 1, _))
             ).count(_.contains("#")).toString
    }
  }
  
  results.foreach(seq => println(seq.mkString))
}