h,w=list(map(int,input().split()))
maze1=[]
for i in range(h):
  maze1.append(list(input()))
from collections import deque
import copy

#スタートする座標をa,bとしておく
def bfs(a,b):
  maze=copy.deepcopy(maze1)
  dp=[[0 for i in range(w)] for j in range(h)]
  q=deque([[a,b]])
  #まず自分がいるところを＃に変えておく
  maze[a][b]="#"
  while len(q)>0:
    i,j=q.popleft()
    if 0<=i+1<=h-1 and 0<=j<=w-1 and maze[i+1][j]==".":
      maze[i+1][j]="#" 
      dp[i+1][j]=dp[i][j]+1
      q.append([i+1,j])
    if 0<=i-1<=h-1 and 0<=j<=w-1 and maze[i-1][j]==".":
      maze[i-1][j]="#"
      dp[i-1][j]=dp[i][j]+1
      q.append([i-1,j])
    if 0<=i<=h-1 and 0<=j-1<=w-1 and maze[i][j-1]==".":
      maze[i][j-1]="#"
      dp[i][j-1]=dp[i][j]+1
      q.append([i,j-1])
    if 0<=i<=h-1 and 0<=j+1<=w-1 and maze[i][j+1]==".":
      maze[i][j+1]="#"
      dp[i][j+1]=dp[i][j]+1
      q.append([i,j+1])
  sum=0
  for i in range(h):
    sum=max(max(dp[i]),sum)
  return sum
  
  
ans=0
for k in range(int(h/2)+1):
  for l in range(w):
    if maze1[k][l]==".":
      ans=max(bfs(k,l),ans)

print(ans)
