import java.lang.Math.max
import java.lang.Math.min

fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(' ').map(String::toInt)
    val ret = Array(h){IntArray(w)}
    for(i in 0 until h){
        readLine()!!.forEachIndexed { j, c ->
            if(c == '#'){
                ret[i][j] = -100
                for(ii in max(0, i-1)..min(h-1, i+1)){
                    for(jj in max(0, j-1)..min(w-1, j+1)){
                        ret[ii][jj]++
                    }
                }
            }
        }
    }
    ret.forEachIndexed {i, it ->
        it.forEach {
            print(if(it < 0) '#' else it)
        }
        if(i < h-1) println()
    }

}