import           Control.Monad
import           Data.Array.IArray
import qualified Data.ByteString.Char8 as BS
main :: IO ()
type Pos = (Int,Int)
main = do
    [h,w] <- map read . words <$> getLine :: IO [Int]
    s <- concat <$> replicateM h (map BS.unpack . BS.words <$> BS.getLine)
    let idxs = (\x y -> (x,y)) <$> [0..h-1] <*> [0..w-1]
        arr :: Array Pos Char
        arr = array ((0,0),(h-1,w-1)) (zip idxs (concat s))
        ms = [bfs arr p | p <- idxs,arr ! p == '.']
        next :: Array Pos Char -> Pos ->  [Pos]
        next s (y,x) = [(ny,nx) | (dy,dx) <- zip [1,0,-1,0] [0,1,0,-1],let (ny,nx) = (y+dy,x+dx),0 <= nx,nx < w,0 <= ny,ny < h,s ! (ny,nx) == '.']

        walk ::Array Pos Char -> Int -> [(Pos,Int)] -> [(Pos,Int)]
        walk _ 0 _ = []
        walk s n ((p,d):ps) = zip ne (repeat (d+1)) ++ walk k (n-1+len) ps
            where   ne = next s p
                    len = length ne
                    k = s // zip ne (repeat '#')

        bfs :: Array Pos Char -> Pos -> Int
        bfs s start = postProcess queue
            where   queue = (start,0) : walk s' 1 queue
                    postProcess = maximum . map snd
                    s' = s // [(start,'#')]
    print $ maximum ms