import java.lang.StringBuilder

fun main(arr:Array<String>) {
    val (h, w) = readLine()!!.split(" ").map { it.toInt() }
    val map = (1..h).map { readLine()!! }
    val ans = (1..h).map { (1..w).toMutableList() }
    for(r in ans.indices) {
        for(c in ans[r].indices) {
            if(map[r][c] == '#') {
                ans[r][c] = 9
                continue
            }
            var cnt = 0
            for(r2 in (Math.max(0, r-1)..Math.min(r+1,ans.lastIndex))) {
                for(c2 in (Math.max(0, c-1)..Math.min(c+1, ans[r].lastIndex))) {
                    if(map[r2][c2] == '#') {
                        cnt++
                    }
                }
            }
            ans[r][c] = cnt
        }
    }
    val ansText = StringBuilder()
    ans.forEach { ansText.appendln(it.map { if(it == 9) "#" else it.toString() }.joinToString("")) }
    print(ansText.toString())
}