(* O(h w) *)
Scanf.scanf " %d %d" @@ fun h w ->
  let ss = Array.init h @@ fun _ -> Scanf.scanf " %s" @@ fun s -> s in
  let f a b =
    let c = ref 0 in
    for y = -1 to 1 do
      for x = -1 to 1 do
        let a_y, b_x = a + y, b + x in
        if 0 <= a_y && a_y < h && 0 <= b_x && b_x < w then
          if ss.(a_y).[b_x] = '#' then incr c
      done
    done;
    !c in
  for y = 0 to h - 1 do
    for x = 0 to w - 1 do
      if ss.(y).[x] = '.' then print_int @@ f y x else print_char '#'
    done;
    print_newline ()
  done