import java.util.*

val sc = Scanner(System.`in`)
val H = sc.nextInt()
val W = sc.nextInt()
val S = Array(H) { sc.next() }

fun main(args: Array<String>) {
    val cntA = Array(H) { Array(W) { 0 } }
    for (i in 0 until H) {
        for (j in 0 until W) {
            if (S[i][j] == '#') {
                cntA[i][j] = 10
                for (y in -1..1) {
                    for (x in -1..1) {
                        if (i + y in 0 until H && j + x in 0 until W) {
                            cntA[i + y][j + x]++
                        }
                    }
                }
            }
        }
    }
    for (i in 0 until H) {
        for (j in 0 until W) {
            if (cntA[i][j] >= 10) {
                print('#')
            } else {
                print(cntA[i][j])
            }
        }
        println()
    }
}
