import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val h, w = sc.nextInt()
    val map = Array.ofDim[Char](h, w)

    for (i <- 0 until h) {
      val s = sc.next()
      map(i) = s.toCharArray
    }

    for (i <- 0 until h) {
      for (j <- 0 until w) {
        if (map(i)(j) != '#') {
          val m = Array((i, j + 1), (i + 1, j), (i + 1, j + 1), (i - 1, j), (i, j - 1), (i - 1, j - 1), (i + 1, j - 1), (i - 1, j + 1))
          val n = m.filter(n =>
            0 <= n._1 && n._1 < h && 0 <= n._2 && n._2 < w
          )
          var ca = 0
          for (k <- n.indices) {
            if (map(n(k)._1)(n(k)._2) == '#') ca += 1
          }
          print(ca)
        } else {
          print('#')
        }
      }
      println()
    }
  }
}