fun main(args: Array<String>) = yorukatsu17b()

fun yorukatsu17b() {
    val (h, w) = readLine()!!.split(' ').map { it.toInt() }
    val grid = (1..h).map { readLine()!!.toCharArray() }

    val answer = grid.mapIndexed { y, row ->
        row.mapIndexed { x, c ->
            if (c == '#') c else {
                around.map { y + it.first to x + it.second }
                    .filter { it.first in 0 until h && it.second in 0 until w }
                    .count { grid[it.first][it.second] == '#' }
            }
        }.joinToString("")
    }.joinToString(System.lineSeparator())

    println(answer)
}

private val around = (-1..1).map { i1 -> (-1..1).map { i2 -> i1 to i2 } }.flatten().filterNot { it == 0 to 0 }
