import sys
input = sys.stdin.readline

H,W = (int(x) for x in input().rstrip('\n').split())

m = []
for i in range(H):
  S = list(input().rstrip('\n'))
  m.append(S)
r = []
for x in range(W):
  for y in range(H):
    if m[y][x] == '.':
      r.append((x,y))
res = 0
for x,y in r:
  res_n = 0
  ok = [(x,y)]
  used = []
  while len(ok) > 0 :
    ok_n = []
    for X,Y in ok:
      next = [(X+1,Y),(X-1,Y),(X,Y-1),(X,Y+1)]
      next = [i for i in next if i not in used]
      for i in next:
        if all([i[0]>=0,i[0]<W,i[1]<H,i[1]>=0]):
          if m[i[1]][i[0]]=='.':
            ok_n.append(i)
    used.extend(ok)
    ok = ok_n
    if len(ok)>0:
      res_n += 1
  if res < res_n:
    res = res_n
print(res)