(defn get_H_W []
  (->> (clojure.string/split (read-line) #"\s")
    (map #(Integer/parseInt %))))

(defn set_Array [^"[[C" Array H W]
  (dotimes [h H]
    (->> (read-line)
      (char-array W)
      (aset Array h))))

(defn Minesweeper [^"[[C" Array H W]
  (doseq [x (range W)
          y (range H)
          :let [v ^char (aget ^"[C" (aget Array y) x)]
          :when (not= \# v)]
    (->>
      (with-local-vars [counts 0]
        (doseq [d-y-x [[-1 -1] [-1 0] [-1 1] [0 -1] [0 1] [1 -1] [1 0] [1 1]]
                :let [[dy dx] (map + (list y x) d-y-x)]
                :when (and
                        (<= 0 dx)
                        (< dx W)
                        (<= 0 dy)
                        (< dy H)
                        (= \# (aget ^"[C" (aget Array dy) dx)))]
          (var-set counts (unchecked-inc-int  @counts)))
        @counts)
      (unchecked-add-int (unchecked-int \0))
      unchecked-char
      (aset ^"[C" (aget Array y) x))))

(defn output [^"[[C" Array]
  (-> (areduce Array idx ret ""
        (str ret
          (apply str (aget Array idx))
          "\n"))
    print))

(let [[H W] (get_H_W)]
  (doto (make-array Character/TYPE H W)
    (set_Array H W)
    (Minesweeper H W)
    (output)))