open Queue
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 q = create ()
let f (sy, sx) (gy, gx) = let ds = Array.make_matrix h w ~-1 in push (sy, sx) q; ds.(sy).(sx) <- 0;
  while not @@ is_empty q do let y0, x0 = pop q in List.iter (fun (dy, dx) -> let y, x = y0 + dy, x0 + dx in if 0 <= y && y < h && 0 <= x && x < w && ds.(y).(x) = -1 && ss.(y).[x] = '.' then (push (y, x) q; ds.(y).(x) <- ds.(y0).(x0) + 1)) [-1, 0; 0, -1; 1, 0; 0, 1] done; ds.(gy).(gx)
let ans = ref 0
let _ = for sy = 0 to h - 1 do for sx = 0 to w - 1 do for gy = 0 to h - 1 do for gx = 0 to w - 1 do ans := max !ans (f (sy, sx) (gy, gx)) done done done done; Printf.printf "%d\n" !ans