(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 [^"[[C" Array H W]
  (dotimes [h H]
    (->> (read-line)
      (char-array W)
      (aset ^"[[C" Array h))))


(defn Minesweeper [^"[[C" Array H W]
  (let [X (range W)
        Y (range H)]
    (doseq [x X
            y Y
            :let [v ^char (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)
                         (= \# ^char (aget ^"[C" (aget ^"[[C" Array dy) dx)))]
             true)
        count
        (unchecked-add-int one)
        unchecked-char
        (aset ^"[C" (aget ^"[[C" Array y) x)))))

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

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