    fun main(args: Array<String>) {
        val sc = if (args.size > 1) java.util.Scanner(java.io.File(args[1])) else java.util.Scanner(System.`in`)
        solve(sc)
    }

    fun solve(sc: java.util.Scanner) {
        val H = sc.nextInt()
        val W = sc.nextInt()
        sc.nextLine()
        val S: Array<CharArray> = (1..H).map { sc.nextLine().toCharArray() }.toTypedArray()
        (0..(H - 1)).forEach { y ->
            (0..(W - 1)).forEach { x ->
                if (S[y][x] == '.') {
                    val n = arrayOf(
                            -1 to -1,
                            -1 to 0,
                            -1 to 1,
                            0 to -1,
                            0 to 1,
                            1 to -1,
                            1 to 0,
                            1 to 1
                    ).map { d ->
                        try {
                            S[y + d.first][x + d.second] == '#'
                        } catch (e: ArrayIndexOutOfBoundsException) {
                            false
                        }
                    }.count { it }
                    S[y][x] = "%d".format(n).toCharArray()[0]
                }
            }
        }
        S.forEach { println(it.joinToString("")) }
    }
