fun main(args:Array<String>) {
    val (H,W)=readLine()!!.split(" ").map(String::toInt)
    val blocks=(1..H).map{readLine()!!}.map {
      it.map {c->
        if(c=='#') {true} else {false}
      }
    }
    blocks.indices.map{
      Pair(it,blocks[it])
    }.map {
      val (i,row) = it
      (0.until(row.size)).map {j->
       if(blocks[i][j]) {
         "#"
       } else {
        val num = 
        listOf(Pair(i-1,j-1),Pair(i-1,j),Pair(i-1,j+1),
        Pair(i,j-1),Pair(i,j+1),
        Pair(i+1,j-1),Pair(i+1,j),Pair(i+1,j+1))
        .filter {pair->
          pair.first >=0 && pair.first <H && pair.second >=0 && pair.second < W
        }.map {pair->
          blocks[pair.first][pair.second]
        }.filter {isMine-> isMine}.size
        "${num}"
       }
      }
      .joinToString("")
    }.forEach {
      println(it)
    }
  }
