from collections import deque
#import numpy as np

h,w=map(int,input().split())
#sy,sx=map(int,input().split())
#sy=sy-1
#sx=sx-1
#gy,gx=map(int,input().split())
#gy=gy-1
#gx=gx-1
maze=[list("#"*(w+2))]+[list("#"+input()+"#") for i in range(h)]+[list("#"*(w+2))]
INF=10800 #>50*50
visited=[[-INF]*(w+2) for i in range(h+2)]

ss=[]

for i in range(1,h+1):
  for j in range(1,w+1):
    if maze[i][j]==".":
      ss.append((i,j))



def bfs(maze,visited,sy,sx):#,gy,gx):
  queue=deque([[sy,sx]])
  visited[sy][sx]=0
  while queue:
    [y,x]=queue.popleft()
    #if (y,x)==(gy,gx):
    #  return visited[gy][gx]
    for i,j in ((-1,0),(1,0),(0,1),(0,-1)):
      #もともと壁があって、はみ出す心配はない。
      y_new,x_new=y+i,x+j
      if maze[y_new][x_new]=="." and visited[y_new][x_new]==-INF:
        visited[y_new][x_new]=visited[y][x]+1
        queue.append([y_new,x_new])

        
        
ans=0
for i,j in ss:
  bfs(maze,visited,3,1)
  for i in range(1,h+1):
    for j in range(1,w+1):
      ans=max(ans,visited[i][j])

    
    
print(ans)

