(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 input []
  (let [[H W] (->> (clojure.string/split (read-line) #"\s")
                (map #(Integer/parseInt %)))]
    (list H W
      (->> (loop [h H s '[]]
             (if (zero? h)
               s
               (recur
                 (unchecked-dec-int h)
                 (conj s
                   (into-array Character (read-line))))))
        into-array))))

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

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

(let [[H W ^"[[Ljava.lang.Character" Array] (input)]
  (do (Minesweeper H W Array)
      (output Array)))