import java.lang.StringBuilder

fun main(arr:Array<String>) {
    val (h,w) = readLine()!!.split(" ").map { it.toInt() }
    val map = (1..h).map { readLine()!! }
    for(i in map.indices) {
        val line = StringBuilder()
        for(j in map[i].indices) {
            if(map[i][j] == '#') {
                line.append("#")
                continue
            }
            var cnt = 0
            for(k in (i-1..i+1)) {
                if(k < 0 || k >= h) {
                    continue
                }
                for(l in (j-1..j+1)) {
                    if(l < 0 || l >= w) {
                        continue
                    }
                    if(k == i && l == j) {
                        continue
                    }
                    if(map[k][l] == '#') {
                        cnt++
                    }
                }
            }
            line.append(cnt)
        }
        println(line.toString())
    }
}
