(set! *unchecked-math* true)
(def ^:const D-Y-X
  [[-1 -1] [-1 0] [-1 1] [0 -1] [0 1] [1 -1] [1 0] [1 1]])

(def ^:const one (unchecked-int \0))

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

(defn set_Array [H W ^"[[C" Array]
  (loop [h 0]
    (when (< h H)
      (do (->> (read-line)
            (char-array W)
            (aset ^"[[C" Array h))
          (recur (unchecked-inc-int h))))))


(defn Minesweeper [H W ^"[[C" Array]
  (let [X (range W)
        Y (range H)]
    (dorun
      (for [x X
            y Y
            :let [v (aget ^"[C" (aget ^"[[C" Array y) x)]
            :when (not= \# v)]
        (->> (for [d-y-x D-Y-X
                   :let [[dy dx] (map + (list y x) d-y-x)]
                   :when (and
                           (<= 0 dx)
                           (< dx W)
                           (<= 0 dy)
                           (< dy H)
                           (= \# (aget ^"[C"(aget ^"[[C"Array dy) dx)))]
               true)
          count
          (unchecked-add-int one)
          unchecked-char
          (aset ^"[C"(aget^"[[C" Array y) x))))))

(defn output [^chars Array]
  (->> Array
    (map #(apply str %))
    (map println-str)
    (apply str)
    println))

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