import           Control.Exception     (assert)
import           Control.Monad
import qualified Control.Monad.ST      as ST
import qualified Data.Array.ST         as ST
import qualified Data.Array.Unboxed    as A
import qualified Data.ByteString.Char8 as BS
import           Data.List
import           Data.Maybe

warshallFloyd :: A.UArray (Int, Int) Int -> A.UArray (Int, Int) Int
warshallFloyd iarr = oarr
  where
    l  = (fst . fst . A.bounds) iarr
    l' = (snd . fst . A.bounds) iarr
    r  = (fst . snd . A.bounds) iarr
    r' = (snd . snd . A.bounds) iarr
    oarr = assert (l==l' && r==r') $ ST.runSTUArray $ do
      d <- ST.thaw iarr
      forM_ [l..r] $ \k ->
        forM_ [l..r] $ \i ->
          forM_ [l..r] $ \j -> do
            dik <- ST.readArray d (i,k)
            dkj <- ST.readArray d (k,j)
            dij <- ST.readArray d (i,j)
            when (dik + dkj < dij) $
              ST.writeArray d (i,j) (dik + dkj)
      return d

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  let infty = 10^6 :: Int

  [h, w] <- getIntList
  g <- replicateM h getLine

  let pos y x | (x < 0 || x >= w || y < 0 || y >= h) = False
              | otherwise = let c = (g !! y) !! x
                            in c == '.'

      arr = ST.runSTUArray $ do
        marr <- ST.newArray ((0,0),(h*w-1,h*w-1)) infty
        forM_ [0..(h-1)] $ \y -> do
          forM_ [0..(w-1)] $ \x -> do
            when (pos y x) $ do
              let p0 = y*w+x
              ST.writeArray marr (p0,p0) 0
              when (pos y (x-1)) $ ST.writeArray marr (p0,y*w+x-1) 1
              when (pos y (x+1)) $ ST.writeArray marr (p0,y*w+x+1) 1
              when (pos (y+1) x) $ ST.writeArray marr (p0,(y+1)*w+x) 1
              when (pos (y-1) x) $ ST.writeArray marr (p0,(y-1)*w+x) 1
        return marr

      arr' = warshallFloyd arr

      ans = maximum $
        map (\((_,_),d) -> if d < infty then d else 0) $ A.assocs arr'

  print ans