from collections import deque
def bfs(yy,xx):
  global ans
  d=[[float('inf')]*w for i in range(h)]
  dx=[1,0,-1,0]
  dy=[0,1,0,-1]
  q=deque([])
  q.append((yy,xx))
  d[yy][xx]=0
  while q:
    y,x=q.popleft()
    for i in range(4):
      ny,nx=y+dy[i],x+dx[i]
      if 0<=ny<h and 0<=nx<w and s[ny][nx]=='.' and d[ny][nx]==float('inf'):
        d[ny][nx]=d[y][x]+1
        q.append((ny,nx))
        if ans<d[ny][nx]:
          ans=d[ny][nx]
  return ans
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
a=0
ans=0
for i in range(h):
  for j in range(w):
    if s[i][j]=='.':
      a=max(a,bfs(i,j))
print(a)