(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
                 (dec h)
                 (conj s
                   (into-array Character
                     (clojure.string/replace (read-line) #"\." "0"))))))
        into-array))))

(defn Minesweeper [[H W ^chars Array]]
  (let [targets (for [x (range W)
                      y (range H)
                      :when (= \# (aget ^chars Array y x))]
                  (list x y))]
    (doall
      (for [target targets
            x' (condp = (first target)
                 0 '(0 1)
                 (dec W) '(-1 0)
                 '(-1 0 1))
            y' (condp = (second target)
                 0 '(0 1)
                 (dec H) '(-1 0)
                 '(-1 0 1))
            :let [x'' (+ (first target) x')
                  y'' (+ (second target) y')
                  v (aget ^ chars Array y'' x'')]
            :when (not= \# v)]
        (aset ^chars Array y'' x'' (unchecked-char (unchecked-inc-int (unchecked-int v)))))))
  Array)

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

(->> (input)
  Minesweeper
  output)