import sequtils, strutils
import macros
macro unpack(s:seq, n:static[int]): auto =
  let t = genSym()
  result = quote do:(let `t` = `s`;())
  when NimMajor == 0 and NimMinor <= 17:
    for i in 0..<n: result[0][1].add(quote do:(`t`[`i`]))
  else:
    for i in 0..<n: result[1].add(quote do:(`t`[`i`]))

const
  inf = 1 shl 30
let
  (h, w) = stdin.readline.split.map(parseInt).unpack(2)
  sss = newSeqWith(h, stdin.readline)
var
  dss = newSeqWith(h*w, newSeqWith(h*w, inf))

for i in 1..<h:
  if sss[i][0] == '.' and sss[i-1][0] == '.':
    dss[i*w][(i-1)*w] = 1
    dss[(i-1)*w][i*w] = 1
for i in 1..<w:
  if sss[0][i] == '.' and sss[0][i-1] == '.':
    dss[i][i-1] = 1
    dss[i-1][i] = 1
for i in 1..<h:
  for j in 1..<w:
    if sss[i][j] == '.' and sss[i-1][j] == '.':
      dss[i*w+j][(i-1)*w+j] = 1
      dss[(i-1)*w+j][i*w+j] = 1
    if sss[i][j] == '.' and sss[i][j-1] == '.':
      dss[i*w+j][i*w+j-1] = 1
      dss[i*w+j-1][i*w+j] = 1

for k in 0..<(h*w):
  for i in 0..<(h*w):
    for j in 0..<(h*w):
      dss[i][j] = min(dss[i][j], dss[i][k]+dss[k][j])

echo dss.mapIt(it.filterIt(it != inf)).filterIt(len(it) > 0).mapIt(max(it)).max
