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 if ss.(i).[j] = '#' then print_char '#' else print_int @@ List.fold_left (fun 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) 0 [-1, 0; -1, -1; 0, -1; 1, -1; 1, 0; 1, 1; 0, 1; -1, 1] done; print_newline () done