let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let (h, w) = Scanf.sscanf (read_line ()) "%d %d" @@ fun h w -> (h, w)
let s = Array.init h @@ fun _ -> read_line () |> split_string |> Array.of_list

let rec start i j = if s.(i).(j) = "." then (i, j) else if j = w - 1 then start (i + 1) 0 else start i (j + 1)
let (si, sj) = start 0 0

let walk i j arr =
  let que = Queue.create () in
  Queue.add (i, j) que;
  while not (Queue.is_empty que) do
    let (i, j) = Queue.pop que in
    List.iter (fun (di, dj) -> 
      if 0 <= di && di < h && 0 <= dj && dj < w && s.(di).(dj) = "."  && arr.(di).(dj) = -1 then begin
        arr.(di).(dj) <- arr.(i).(j) + 1;
        Queue.add (di, dj) que
      end
    ) [(i - 1, j); (i + 1, j); (i, j - 1); (i, j + 1)]
  done

let f arr =
  let pos = ref (0, 0) in
  let m = ref 0 in
  for i = 0 to h - 1 do
    for j = 0 to w - 1 do
      if !m < arr.(i).(j) then begin
        m := arr.(i).(j);
        pos := (i, j)
      end
    done
  done;
  (!pos, !m)

let () =
  let arr = Array.init h @@ fun _ -> Array.make w (-1) in
  arr.(si).(sj) <- 0;
  walk si sj arr;
  let (si, sj) = fst (f arr) in
  let arr = Array.init h @@ fun _ -> Array.make w (-1) in
  arr.(si).(sj) <- 0;
  walk si sj arr;
  Printf.printf "%d\n" @@ snd (f arr) + 1