fun main(args: Array<String>) {
    val (h, w) = readLine()?.split(" ")?.map { it.toInt() } ?: return
    val grid: List<List<String>> = (0 until h).map {
        readLine()?.toCharArray()?.map { it.toString() } ?: listOf()
    }
    // 空きマスを0に、爆弾を-1に変換
    val result = grid.map { list -> list.map {
        if (it == ".") 0 else - 1
    }.toMutableList() }.toMutableList()

    for ((i, list) in result.withIndex()) {
        for ((j, c) in list.withIndex()) {
            if (c >= 0) {
                continue
            }

            val hasUpSpace = i > 0
            val hasBottomSpace = i < h - 1
            val hasLeftSpace = j > 0
            val hasRightSpace = j < w - 1

            // 上
            if (hasUpSpace && result[i - 1][j] != -1) {
                result[i - 1][j] += 1
            }
            // 下
            if (hasBottomSpace && result[i + 1][j] != -1) {
                result[i + 1][j] += 1
            }
            // 左
            if (hasLeftSpace && result[i][j - 1] != -1) {
                result[i][j - 1] += 1
            }
            // 右
            if (hasRightSpace && result[i][j + 1] != -1) {
                result[i][j + 1] += 1
            }
            // 左上
            if (hasUpSpace && hasLeftSpace && result[i - 1][j - 1] != -1) {
                result[i - 1][j - 1] += 1
            }
            // 右上
            if (hasUpSpace && hasRightSpace && result[i - 1][j + 1] != -1) {
                result[i - 1][j + 1] += 1
            }
            // 左下
            if (hasBottomSpace && hasLeftSpace && result[i + 1][j - 1] != -1) {
                result[i + 1][j - 1] += 1
            }
            // 右下
            if (hasBottomSpace && hasRightSpace && result[i + 1][j + 1] != -1) {
                result[i + 1][j + 1] += 1
            }
        }
    }

    result.forEach { list ->
        list.forEach {
            if (it == -1) {
                print("#")
            } else {
                print(it)
            }
        }
        print("\n")
    }
}