object Main extends App {
	val hw = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	val s = Array.ofDim[Int](hw(0)+2, hw(1)+2)

	var list = List[(Int, Int)]()

	for(i<-1 to hw(0)){
		val temp = scala.io.StdIn.readLine.toArray

		for(j<-0 until hw(1)){
			temp(j) match {
				case '#' => {
					list = (i,j)::list
					s(i-1)(j+0) += 1
					s(i-1)(j+1) += 1
					s(i-1)(j+2) += 1
					s(i+0)(j+0) += 1
					s(i+0)(j+2) += 1
					s(i+1)(j+0) += 1
					s(i+1)(j+1) += 1
					s(i+1)(j+2) += 1
				}
				case _ =>
			}
		}
	}

	for(i<-list){
		s(i._1)(i._2 + 1) = -1
	}

	for(i<-1 to hw(0)){
		for(j<-1 to hw(1)){
			if(s(i)(j) == -1) print("#")
			else print(s(i)(j))
		}
		println(" ")
	}
}