let () = Scanf.scanf "%d %d\n" @@ fun h w ->
  let ss = Array.init h @@ fun _ ->
    Scanf.scanf "%s\n" @@ fun s -> s in
  let dx = [| 1; 1; 0; -1; -1; -1; 0; 1 |] in
  let dy = [| 0; 1; 1; 1; 0; -1; -1; -1 |] in
  Array.iteri (fun i s ->
    print_endline @@ String.mapi (fun j c ->
      if c = '#' then '#'
      else
        Array.init 8 (fun n -> n)
        |> Array.to_list
        |> List.filter (fun n ->
            try ss.(i + dy.(n)).[j + dx.(n)] = '#' with _ -> false)
        |> List.length
        |> ( + ) (Char.code '0')
        |> Char.chr) s) ss