let h, w = Scanf.scanf " %d %d" @@ fun a b -> a, b
let ss = Array.init h @@ fun _ -> Scanf.scanf " %s" @@ fun s -> s
let _ =
  for i = 0 to h - 1 do
    for j = 0 to w - 1 do
      let f c (dy, dx) =
        let y, x = i + dy, j + dx in if 0 <= y && y < h && 0 <= x && x < w && ss.(y).[x] = '#' then c + 1 else c in
      if ss.(i).[j] = '.' then print_int @@ List.fold_left f 0 [-1, 0; -1, -1; 0, -1; 1, -1; 1, 0; 1, 1; 0, 1; -1, 1]
      else print_char ss.(i).[j] done; print_newline () done