open Batteries
let () =
  let h,w = Scanf.scanf "%d %d " (fun a b -> a,b) in

  let mat = Array.init h (fun _ ->
      Array.init w (fun _ -> Scanf.scanf "%c " (fun a -> if a = '.' then '0' else a))
    ) in

  for i=0 to h-1 do
    for j=0 to w-1 do
      if mat.(i).(j) = '#' then (
        for i2=i-1 to i+1 do
          for j2=j-1 to j+1 do
            try
              if mat.(i2).(j2) <> '#' then
                mat.(i2).(j2) <- char_of_int @@ (int_of_char  mat.(i2).(j2)) + 1
            with _ -> ()

          done;
        done;
      ) else ()
    done;
  done;

  Array.iter (fun arr -> Array.iter (print_char) arr; print_endline "") mat;
