open Printf
open Scanf

let () =
  let h, w = scanf "%d %d " (fun x y -> (x, y)) in
  let ar = Array.make_matrix h w 0 in
  let rec read i =
    if i = h then () else
      let s = scanf "%s " (fun x -> x) in
      String.iteri (fun j c -> if c = '#' then ar.(i).(j) <- (-1) else ()) s;
      read (i + 1) in
  read 0;
  let idx i j = [(i+1, j);(i-1, j);(i, j+1);(i, j-1);(i-1, j-1);(i-1, j+1);(i+1, j-1);(i+1, j+1)] |>
                   List.filter (fun (x, y) -> x >= 0 && x < h && y >= 0 && y < w) in
  Array.iteri (fun i a ->
               Array.iteri (fun j v ->
                            if v = (-1) then
                              List.iter (fun (x, y) ->
                                         if ar.(x).(y) >= 0 then
                                           ar.(x).(y) <- ar.(x).(y) + 1 else ()) (idx i j) else ()) a) ar;
  Array.iter (fun a -> Array.iter (fun v -> if v = (-1) then printf "#" else printf "%d" v) a; printf "\n") ar
