import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val h = sc.nextInt()
    val w = sc.nextInt()
    val t = (1..h).map { sc.next().toCharArray().map { if (it == '.') '0' else it }.toMutableList() }
    val dx = arrayOf(-1, 0, 1, -1, 1, -1, 0, 1)
    val dy = arrayOf(-1, -1, -1, 0, 0, 1, 1, 1)
    repeat(h) {i->
        repeat(w) {j->
            if (t[i][j] == '#') {
                for (k in dx.indices) {
                    val nx = j + dx[k]
                    val ny = i + dy[k]
                    if ((nx in 0 until w) && (ny in 0 until h) && t[ny][nx] != '#') {
                        t[ny][nx]++
                    }
                }
            }
        }
    }

    repeat(h) {
        println(t[it].joinToString(""))
    }
}