import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (h, w) = listOfInt()
    var lines = mutableListOf<String>()

    repeat(h) {
        lines.add(next())
    }

    for (i in 0 until h) {
        for (j in 0 until w) {
            if (lines[i][j] == '#') continue

            var cnt = 0

            if (i > 0 && j > 0 && lines[i-1][j-1] == '#') cnt++ // top-left
            if (i > 0 && lines[i-1][j] == '#') cnt++ // top
            if (i > 0 && j < w-1 && lines[i-1][j+1] == '#') cnt++ // top-right
            if (j > 0 && lines[i][j-1] == '#') cnt++ // left
            if (j < w-1 && lines[i][j+1] == '#') cnt++ // right
            if (i < h-1 && j > 0 && lines[i+1][j-1] == '#') cnt++ // bottom-left
            if (i < h-1 && lines[i+1][j] == '#') cnt++ // bottom
            if (i < h-1 && j < w-1 && lines[i+1][j+1] == '#') cnt++ // bottom-right

            lines[i] = lines[i].take(j) + cnt + lines[i].takeLast(w-j-1)
        }
        println(lines[i])
    }
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}