fun main(arr: Array<String>) {
    val (h,w) = readLine()!!.split(" ").map { it.toInt() }
    val map = (1..h).map { readLine()!! }
    val ans = map.indices.map { r -> map[r].indices.map { c-> mineCount(r,c,map) } }
    ans.forEach { println(it.joinToString("")) }
}

fun mineCount(r:Int, c:Int, map:List<String>):Char {
    if(map[r][c] == '#') {
        return '#'
    }
    var cnt = 0
    for(i in (r-1..r+1)) {
        if(i < 0) {
            continue
        }
        if(i > map.lastIndex) {
            continue
        }
        for(j in (c-1..c+1)) {
            if(j < 0) {
                continue
            }
            if(j > map[i].lastIndex) {
                continue
            }
            if(map[i][j] == '#') {
                cnt++
            }
        }
    }
    return cnt.toString()[0]
}