object Main extends App {
	val input: Seq[Array[Char]] = io.Source.stdin.getLines.toSeq.tail.map(' ' +: _.toArray :+ ' ')
	val wall = input.head.map(_ => 'w')
	val walled: Array[Array[Char]] = (wall +: input :+ wall).toArray

	private def func(x: Int, y: Int): Char =
		if (walled(x)(y) == '#') '#' else Seq(
			walled(x - 1)(y - 1),
			walled(x - 1)(y),
			walled(x - 1)(y + 1),
			walled(x)(y - 1),
			walled(x)(y + 1),
			walled(x + 1)(y - 1),
			walled(x + 1)(y),
			walled(x + 1)(y + 1)).count(_ == '#').toString.head

	(1 until walled.length - 1).foreach { l =>
		(1 until walled(0).length - 1).foreach { e =>
			walled(l)(e) = func(l, e)
		}
	}

	(1 until walled.length - 1).foreach { l =>
		println((1 until walled(0).length - 1).map(e => walled(l)(e)).mkString(""))
	}
}
