import sys
sys.setrecursionlimit(10**7)
H, W=map(int, input().split())

S=['#'*(W+2)]+['#'+input()+'#' for i in range(H)]+['#'*(W+2)]

#幅優先探索を実装したい人生だった
def f(x, y, num=0):
  t=num+1
  m[x][y]=t
  if (m[x+1][y]==-1 or m[x+1][y]>t+1) and S[x+1][y]=='.':
    t2=f(x+1, y, t)
    if t<t2:
      t=t2
  if (m[x-1][y]==-1 or m[x-1][y]>t+1) and S[x-1][y]=='.':
    t2=f(x-1, y, t)
    if t<t2:
      t=t2
  if (m[x][y+1]==-1 or m[x][y+1]>t+1) and S[x][y+1]=='.':
    t2=f(x, y+1, t)
    if t<t2:
      t=t2
  if (m[x][y-1]==-1 or m[x][y-1]>t+1) and S[x][y-1]=='.':
    t2=f(x, y-1, t)
    if t<t2:
      t=t2
  return t
out=0
for h in range(1, H+1):
  for w in range(1, W+1):
    if S[h][W]=='#':
      continue
    m=[[-2]*(W+2)]+[[-2]+[-1]*W+[-2] for i in range(H)]+[[-2]*(W+2)]
    tmp=f(h, w)
    if out<tmp:
      out=tmp
print(out)