fun main(args: Array<String>) = run {
    val (h,w) = readLine()!!.split(" ").map { it.toInt() }
    val s = (1..h).map { readLine()!! }

    val ms = Array(h) { IntArray(w) }
    for (i in s.indices) {
        for (j in s[i].indices) {
            if (s[i][j] == '.') continue
            for (dx in -1..1) for (dy in -1..1) {
                val x = j+dx
                val y = i+dy
                if(x in 0..w-1 && y in 0..h-1) ms[y][x]++
            }
        }
    }

    for (i in s.indices) {
        for (j in s[i].indices) {
            print(if (s[i][j]=='#') "#" else ms[i][j])
        }
        println()
    }

}
