fun main(args: Array<String>) {
    val(h,w) = readLine()!!.split(" ").map { it.toInt() }
    val s = (1..h).map { readLine()!! }
    val board = Array(h+2){ BooleanArray(w+2) }
    for(i in 1..h)for(j in 1..w) board[i][j]=s[i-1][j-1]=='#'

    val sb = StringBuilder()
    for(i in 1..h){
        for(j in 1..w){
            if(board[i][j]) {
                sb.append("#")
            } else {
                (-1..1).map { dx ->
                    (-1..1).map { dy ->
                        board[i + dy][j + dx]
                    }
                }.flatten().count { it == true }.let { sb.append(it) }
            }
        }
        sb.append("\n")
    }
    println(sb)
}