fun main(){
    val (h,w) = readLine()!!.split(" ").map{it.toInt()}
    val s = MutableList(h){
        readLine()!!.toString().toCharArray()
    }

    val dx = listOf(0, 0, 1, 1, 1, -1, -1, -1)
    val dy = listOf(1, -1, 0, 1, -1, 0, 1, -1)

    for(i in 0 until h){
        for(j in 0 until w) {
            var count = 0
            if (s[i][j] == '.') {
                for(k in 0 .. 7)
                if (
                        (i + dx[k]) in 0 until h &&
                        (j + dy[k]) in 0 until w &&
                        s[i + dx[k]][j + dy[k]] == '#'
                ) {
                    count++
                }
                //println(count)
                s[i][j] = "$count"[0]
            }
        }
    }
    s.forEach{
        it.forEach { char ->
            print(char)
        }
        println("")
    }

}
