object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val h, w = sc.nextInt()
  val s = Array.fill(h)(sc.next())

  val ans = Array.fill(h, w)("#");
  for {
    i <- 0 until h
    j <- 0 until w
    if s(i)(j) == '.'
  } {
    var n = 0
    for {
      di <- -1 to 1
      dj <- -1 to 1
    } {
      val i1 = i + di
      val j1 = j + dj
      if (0 <= i1 && i1 < h && 0 <= j1 && j1 < w && s(i1)(j1) == '#') {
        n += 1
      }
    }
    ans(i)(j) = n.toString
  }

  ans.map(_.mkString).foreach(println)
}
