import java.lang.Math.max
import java.lang.Math.min

fun main(args: Array<String>) {
    abc075b()
}

fun abc075b() {
    val (h, w) = readLine()!!.split(" ").map { it.toInt() }
    val sList = (1..h).map { readLine()!!.toCharArray() }

    val answer = sList.mapIndexed { y, list ->
        list.mapIndexed { x, c ->
            if (c == '#') c.toString() else {
                val square = sList.slice(max(0, y - 1)..min(y + 1, h - 1))
                    .map { it.slice(max(0, x - 1)..min(x + 1, w - 1)) }
                square.map { it.count { it == '#' } }.sum().toString()
            }
        }.joinToString("")
    }

    println(answer.joinToString(System.lineSeparator()))
}
