private val scanner = java.util.Scanner(System.`in`)

private fun readInts(n: Int) = Array(n) { scanner.nextInt() }
private fun readLongs(n: Int) = Array(n) { scanner.nextLong() }
private fun readLineInts() = readLine()!!.split(" ").map { it.toInt() }.toTypedArray()
private fun readLineLongs() = readLine()!!.split(" ").map { it.toLong() }.toTypedArray()

fun main(args: Array<String>) {
    val (H, W) = readLineInts()
    val S = Array(H) { readLine()!! }

    S.forEachIndexed { indexLine, line ->
        line.forEachIndexed { indexRow, ch ->
            print(
                if (ch == '.') {
                    var sum = 0
                    for (x in -1..1) for (y in -1..1) {
                        if (x == 0 && y == 0) continue
                        try {
                            if (S[indexLine + x][indexRow + y] == '#') ++sum
                        } catch (ignored: Throwable) {
                            continue
                        }
                    }
                    sum
                } else ch
            )
        }
        println("")
    }
}