(defrecord Pair [^int y ^int x])
(def ^:const D-Y-X
  [(Pair. -1 -1) (Pair. -1 0) (Pair. -1 1)
    (Pair. 0 -1) (Pair. 0 1)
    (Pair. 1 -1) (Pair. 1 0) (Pair. 1 1)])

(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)
          :when (not= \# (aget ^"[C" (aget Array y) x))]
    (with-local-vars [counts (unchecked-int 0)]
      (doseq [d-y-x D-Y-X
              :let [dx (unchecked-add-int x (:x d-y-x))
                    dy (unchecked-add-int y (:y 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)))