import scala.io.StdIn

object Main extends App {

  val Array(h, w) = StdIn.readLine().split(' ').map(_.toInt)
  val a = Array.fill[Char](h + 2, w + 2)(" ".charAt(0))

  (1 to h).foreach { i =>
    a(i) = (" " + StdIn.readLine() + " ").toCharArray
  }

  def countBom(center: (Int, Int)): Int = {

    val offsets = List(
      (-1, -1), (-1, 0), (-1, 1),
      ( 0, -1), ( 0, 0), ( 0, 1),
      ( 1, -1), ( 1, 0), ( 1, 1))

    offsets.foldLeft(0){ (acc, o) =>
      acc + (if (a(center._1 - o._1)(center._2 - o._2) == '#') 1 else 0)
    }
  }


  (1 to h).foreach { i =>
    (1 to w).foreach { k =>
      a(i)(k) = if(a(i)(k) == '#') '#' else countBom((i, k)).toString.charAt(0)
    }
  }

  a.slice(1, h + 1).foreach{ l =>
    println(l.slice(1, w + 1).mkString(""))
  }
  
}
