let () =
  let h, w = Scanf.scanf "%d %d" (fun h w -> h, w) in
  let a = Array.init h (fun _ -> Scanf.scanf " %s" (fun s -> s)) in
  a |> Array.mapi (fun i row -> row
      |> String.mapi (fun j c ->
          if c = '#' then '#' else
            [(1, 0); (1, 1); (0, 1); (-1, 1); (-1, 0); (-1, -1); (0, -1); (1, -1)]
            |> List.map (fun (di, dj) ->
                let i', j' = i+di, j+dj in
                if i' < 0 || h <= i' || j' < 0 || w <= j' then 0
                else if a.(i').[j'] = '#' then 1 else 0)
        |> List.fold_left (+) 0
        |> ((+) 48) |> char_of_int))
  |> Array.iter print_endline
