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

    val result = Array(S.size) { "" }
    for (i in S.indices) {
        for (j in 0 until W) {
            if (S[i][j] == '#') {
                continue
            }
            var sum = 0

            val right = j + 1
            val left = j - 1
            val top = i - 1
            val down = i + 1

            if (0 <= top) {
                if (right < W) {
                    if (S[top][right] == '#') {
                        sum++
                    }
                }
                if (S[top][j] == '#') {
                    sum++
                }
                if (0 <= left) {
                    if (S[top][left] == '#') {
                        sum++
                    }
                }
            }
            if (down < H) {
                if (right < W) {
                    if (S[down][right] == '#') {
                        sum++
                    }
                }
                if (S[down][j] == '#') {
                    sum++
                }
                if (0 <= left) {
                    if (S[down][left] == '#') {
                        sum++
                    }
                }
            }
            if (right < W) {
                if (S[i][right] == '#') {
                    sum++
                }
            }
            if (0 <= left) {
                if (S[i][left] == '#') {
                    sum++
                }
            }
            S[i][j] = sum.toString()[0]
        }
    }

    for (i in S.indices) {
        for (j in 0 until W) {
            print(S[i][j].toString())
        }
        println()
    }
}

