let () =
    let main () =
        let h, w = Scanf.sscanf (read_line ()) "%d %d" (fun h w -> h, w) in
        let s = Array.init h (fun _ -> read_line ()) in
        let dfs x y =
            let m = Array.make_matrix h w (-1) in
            let rec loop depth next = function
                | [] -> if next = [] then depth else loop (depth + 1) [] next
                | (xx, yy) :: tl ->
                        let () = m.(yy).(xx) <- depth in
                        let next = if xx > 0     && m.(yy).(xx - 1) < 0 && s.(yy).[xx-1] = '.' then (xx-1, yy) :: next else next in
                        let next = if xx < w - 1 && m.(yy).(xx + 1) < 0 && s.(yy).[xx+1] = '.' then (xx+1, yy) :: next else next in
                        let next = if yy > 0     && m.(yy - 1).(xx) < 0 && s.(yy-1).[xx] = '.' then (xx, yy-1) :: next else next in
                        let next = if yy < h - 1 && m.(yy + 1).(xx) < 0 && s.(yy+1).[xx] = '.' then (xx, yy+1) :: next else next in
                        loop depth next tl
            in
            if s.(y).[x] = '.' then loop 0 [] [ x, y ] else 0
        in
        let rec loop_h y acc =
            let rec loop_w x acc =
                if x = w then acc else loop_w (x + 1) (max acc (dfs x y))
            in
            if y = h then acc else loop_h (y + 1) (loop_w 0 acc)
        in
        loop_h 0 0 |> Printf.printf "%d\n"
    in
    main ()