fun main(args: Array<String>) {
    val (height, width) = readLine()!!.trim().split(' ').map {it.toInt()}

    val table: Array<Array<Boolean>> = Array(height) {
        Array(width) { false }
    }
    
    (0..(height - 1)).forEach { y ->

        readLine()!!.trim().forEachIndexed { x, s ->
            if (s == '#') {
                table[y][x] = true
            }
        }
    }

    // val openedTable: MutableList<MutableList<String>> = mutableListOf(mutableListOf())

    val openedTable = table.mapIndexed() { y, row ->
        row.mapIndexed { x, b ->
            if (b) {
                "#"
            } else {
                val count: Int = countNearBomb(y, x, table, height, width)
                "${count}"
            }
        }
    }

    openedTable.forEach {row ->
        row.forEach {str ->
            print(str)
        }
        println("")
    }
}

fun countNearBomb(y: Int, x: Int, table: Array<Array<Boolean>>, height: Int, width: Int): Int {
    var count: Int = 0
    (-1..1).forEach {yDiff ->
        (-1..1).forEach {xDiff ->
            val targetY = y + yDiff
            val targetX = x + xDiff
            if (targetY < 0 || targetY >= height ||
                    targetX < 0 || targetX >= width) {

            } else {
                if (table[targetY][targetX]) {
                    count += 1
                }
            }

        }
    }

    return count
}