fun main(args: Array<String>) {
    val (H, W) = readLine()!!.split(" ").map { it.toLong() }
    val S = (0 until H).map { readLine()!! }

    println(
            S.mapIndexed { indexH, h ->
                h.mapIndexed { indexW, w ->
                    if (S[indexH][indexW] == '#') "#"
                    else {
                        var r = 0
                        (-1..1).forEach { a ->
                            (-1..1).forEach { b ->
                                if (S.getOrNull(indexH + a)?.getOrNull(indexW + b) ?: '.' == '#') r++
                            }
                        }
                        r.toString()
                    }
                }.foldRight("") { a, b -> a + b }.plus("\n")
            }.foldRight("") { a, b -> a + b }
    )
}