def main():
  from collections import deque
  H, W = map(int, input().split())
  graph = [['#'] * (W+2) for _ in range(H+2)]
  for i in range(H):
    S = input()
    for j in range(W):
      graph[i+1][j+1] = S[j]

  def dfs(sx, sy, gx, gy):
    q = deque([(sx, sy)])
    dist = [[-1] * (W+2) for _ in range(H+2)]
    dist[sx][sy] = 0
    while q:
      x, y = q.popleft()
      dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
      for dx, dy in dxy:
        nextx = x+dx
        nexty = y+dy
        if(dist[nextx][nexty] >= 0):
          continue
        if(graph[nextx][nexty] == '#'):
          continue
        dist[nextx][nexty] = dist[x][y] + 1
        q.append((nextx, nexty))
    return dist[gx][gy]

  ans = 0  
  for sx in range(1, H+1):
    for sy in range(1, W+1):
      for gx in range(1, H+1):
        for gy in range(1, W+1):
          if(graph[sx][sy] == '.' and graph[gx][gy] == '.'):
            tmp = dfs(sx, sy, gx, gy)
            ans = max(ans, tmp)
          
  print(ans)
  
main()