object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val H, W = sc.nextInt()
  val squares =
    Array.fill(W + 2)('X') +:
      Array.fill(H)('X' +: sc.next().toCharArray :+ 'X') :+
      Array.fill(W + 2)('X')

  val rounds = for (x <- -1 to 1; y <- -1 to 1 if !(x == 0 && y == 0)) yield x -> y
  for (i <- 1 to H; j <- 1 to W if squares(i)(j) != '#') {
    squares(i)(j) = (rounds.count { case (x, y) => squares(i + x)(j + y) == '#' } + '0').toChar
  }

  squares.collect {
    case line if !line.forall(_ == 'X') =>
      line.filterNot(_ == 'X').mkString
  }.foreach(println)
}
