fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(' ').map(String::toInt)
    val field = Array(h) { readLine()!!.toCharArray() }
    for (y in 0 until h) {
        for (x in 0 until w) {
            if (field[y][x] == '#') continue
            var bomb = 0
            for (yy in y - 1..y + 1) {
                if (yy !in 0 until h) continue
                for (xx in x - 1..x + 1) {
                    if (xx !in 0 until w) continue
                    if (field[yy][xx] == '#') {
                        bomb++
                    }
                }
            }
            field[y][x] = '0' + bomb
        }
    }
    field.forEach {
        println(it.joinToString(""))
    }
}
