import queue
def bfs(sx,sy):
  #init
  dist = [[-1 for _ in range(w)] for __ in range(h)]
  dist[sx][sy] = 0
  q = queue.Queue()
  q.put([sx,sy])
  res = 0
  
  while not q.empty():
    vx,vy = q.get()
    
    for dx,dy in [(0,1),(1,0),(-1,0),(0,-1)]:
      x = vx+dx
      y = vy+dy
      if 0<=x<h and 0<=y<w and S[x][y] == "." and dist[x][y]==-1:
        q.put([x,y])
        dist[x][y] = dist[vx][vy]+1
        res = max(res, dist[x][y])
  return res


h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
ans = 0

for i in range(h):
  for j in range(w):
    if S[i][j] == '.':
      ans = max(ans, bfs(i,j))
print(ans)