// https://atcoder.jp/contests/abc075/tasks/abc075_b
import java.lang.Math.*
import java.util.*

fun makeGrid(H:Int, W:Int): Array<Array<String?>> {
    return Array(H) { arrayOfNulls<String?>(W)}
}

fun main(args: Array<String>) {
    val scn = Scanner(System.`in`)
    val H = scn.nextInt()
    val W = scn.nextInt()

    var grid = makeGrid(H+2,W+2)

    for(i in 1..H){
        grid[i] = scn.next().split("").toTypedArray()
    }

    for(i in 1..H){
        for(j in 1..W){
            if(grid[i][j]=="."){
                var cnt=0
                if(grid[i-1][j-1]=="#") cnt++
                if(grid[i-1][j]=="#") cnt++
                if(grid[i-1][j+1]=="#") cnt++
                if(grid[i][j-1]=="#") cnt++
                if(grid[i][j+1]=="#") cnt++
                if(grid[i+1][j-1]=="#") cnt++
                if(grid[i+1][j]=="#") cnt++
                if(grid[i+1][j+1]=="#") cnt++

                grid[i][j] = cnt.toString()
            }
        }
    }


    for(i in 1..H){
        for(j in 1..W){
            print(grid[i][j])
        }
        println("")
    }
}