object Main{
  def outChars(args:Array[Char]){
    args.foreach(print)
  }

  def main(args:Array[String])={
    val sc = new java.util.Scanner(System.in)
    val H = sc.nextInt
    val W = sc.nextInt
    val table = Array.ofDim[Char](H,W)
    for(i <- 0 to H-1){
      val line = sc.next().toCharArray()
      for(j <- 0 to W-1){
        table(i)(j) = line(j)
      }
    }

    for(i <- 0 to H-1){
      for(j <- 0 to W-1){
        if(table(i)(j) == '#'){
          print(table(i)(j))
        }else{
          var cnt = 0
          for(dx <- -1 to 1){
            for(dy <- -1 to 1){
              val nx = i+dx
              val ny = j+dy
              if(nx>=0 && nx<H && ny>=0 && ny<W && table(nx)(ny)=='#'){
                cnt = cnt+1
              }
            }
          }
          print(cnt)
        }
      }
      println()
    }
  }
}
