let () =
  let (h, w) = Scanf.scanf "%d %d" (fun a b -> (a, b)) in
  let queue = Queue.create () in
  let dp = Array.make_matrix h w 0 in
  let field = Array.init h @@ fun i -> Array.init w @@
    fun j -> Scanf.scanf "%c"
      (fun c -> if c == '#' then Queue.push (i,j) queue; c)
  in
  let count = ref 0 in
  while not @@ Queue.is_empty queue do
    let (i,j) = Queue.pop queue in
    List.iter (fun (y, x) ->
        count := dp.(i).(j) + 1;
        dp.(y).(x) <- !count;
        Queue.push (y,x) queue;
        field.(y).(x) <- '#'
      ) @@
    List.filter (fun (y, x) -> y >= 0 && y < h && x >= 0 && x < w && field.(y).(x) == '.') [(i+1,j);(i-1,j);(i,j+1);(i,j-1)];
  done;
  Printf.printf "%d\n" !count