fun main(args: Array<String>) {
    var (h, w) = readIntList()
    val s = List(h) { readString() }

    val ans = List(h) { MutableList(w) { 0 } }

    for (i in 0 until h) {
        for (j in 0 until w) {
            for (x in -1..1) {
                for (y in -1..1) {
                    val di = i + x
                    val dj = j + y
                    if (di < 0 || di >= h) continue
                    if (dj < 0 || dj >= w) continue
                    if (s[di][dj] == '#') {
                        ans[i][j]++
                    }
                }
            }
        }
    }

    for (i in 0 until h) {
        for (j in 0 until w) {
            if (s[i][j] == '#') {
                print('#')
            } else {
                print(ans[i][j])
            }
        }
        println()
    }
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)