fun main(args: Array<String>) {
    val (H,W) = readLine()!!.split(" ").map{ i -> i.toInt() }
    val s = Array(H){readLine()!!.toCharArray()}

    for( h in 0..H-1){
        for( w in 0..W-1){
            print(if(s[h][w]=='#') "#" else count(h,w,s))
        }
        println()
    }
}

fun count(h: Int, w: Int, s: Array<CharArray>): Int {
    var count = 0
    for(i in h-1..h+1){
        if(i < 0 || i >= s.size) continue
        for(j in w-1..w+1){
            if( j < 0 || j >= s[0].size)continue
            if(s[i][j]=='#')count++
        }
    }
    return count
}