# -*- coding: utf-8 -*-
import numpy as np
iH, iW = map(int, input().split())
naAll = np.zeros((iH+2, iW+2), dtype=int) - 1
#0123:udlr
iID0 = 0
for iH0 in range(iH):
  s = input()
  for i, s0 in enumerate(s):
    if s0 == ".":
      naAll[iH0+1, i+1] = iID0
      iID0 += 1
lMaze = [[] for _ in range(iID0)]
lPoss = []
for iH0 in range(iH):
  for iW0 in range(iW):
    if naAll[iH0+1, iW0+1] >= 0:
      iID = naAll[iH0 + 1, iW0 + 1]
      if naAll[iH0 + 2, iW0 + 1] >= 0:
        lMaze[iID].append(naAll[iH0 + 2, iW0 + 1])
      if naAll[iH0 + 1, iW0 + 2] >= 0:
        lMaze[iID].append(naAll[iH0 + 1, iW0 + 2])
      if naAll[iH0    , iW0 + 1] >= 0:
        lMaze[iID].append(naAll[iH0    , iW0 + 1])
      if naAll[iH0 + 1, iW0    ] >= 0:
        lMaze[iID].append(naAll[iH0 + 1, iW0    ])
      if not( (naAll[iH0 + 2, iW0 + 1] >= 0 and \
               naAll[iH0    , iW0 + 1] >= 0) or
              (naAll[iH0 + 1, iW0 + 2] >= 0 and \
               naAll[iH0 + 1, iW0    ] >= 0) ):
        lPoss.append(iID)
      #print(iID, lMaze)
lMax = []
for iID in lPoss:
  lState = [0]*iID0
  lState[iID] = 1
  lMazeNow = [lMaze[iID]]
  iPre        = 1
  iTime       = 0
  while iPre < iID0:
    lMazeNow0 = []
    for lMazeNext in lMazeNow :
      for iIDnext in lMazeNext:
        if lState[iIDnext] == 0:
          lState[iIDnext] = 1
          iPre += 1
          lMazeNow0.append(lMaze[iIDnext])
    lMazeNow = lMazeNow0
    iTime += 1
    #print(iID, iTime, lState)
  lMax.append(iTime)
print(max(lMax))
#print(lMaze)
#print(naAll)