import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val height = sc.nextInt()
    val width = sc.nextInt()

    val grid = Array(height) { sc.next().toCharArray() }


    val dx = arrayOf(-1, -1, -1, 0, 0, 1, 1, 1)
    val dy = arrayOf(-1, 0, 1, -1, 1, -1, 0, 1)
    for (x in 0 until width) {
        for (y in 0 until height) {
            var sum = 0
            if (grid[y][x] != '.') continue
            for (d in 0..7) {
                val nx = x + dx[d]
                val ny = y + dy[d]

                if (nx < 0 || ny < 0 || nx >= width || ny >= height) continue
                if (grid[ny][nx] == '#') sum += 1
            }
            grid[y][x] = '0' + sum
        }
    }
    grid.forEach { println(String(it)) }
}


class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


