from collections import deque
import itertools

H,W = map(int,input().split())
labyrinth = [[] for i in range(H)]
points = []

for i in range(H):
  w = list(input())
  labyrinth[i] = w
  for j in range(W):
    if w[j] == ".":
      points.append([j,i])


com = list(itertools.combinations(points,2))

#移動パターン
movex = [1,0,-1,0]
movey = [0,1,0,-1]

def shortest_path(sx,sy,gx,gy,labyrinth):
  INF = 10 ** 2

  x_length = W
  y_length = H
  distance = [[INF for i in range(x_length)] for j in range(y_length)]
  
  queue = deque()
  queue.append((sx,sy))
  distance[sy][sx] = 0
  
  #幅優先探索
  def bfs():
    #探索候補がある限り
    while len(queue) > 0:
      x,y = queue.popleft()
      
      #ゴールの座標に達したら中止
      if x == gx and y == gy:
        break
        
      for i in range(0, 4):
        nx = x + movex[i]
        ny = y + movey[i]

        #探索迷路内であり
        if (0 <= nx and ny < y_length and 0 <= ny and nx < x_length):
          #通行可能かつ未到達であれば
          if (labyrinth[ny][nx] != "#"  and distance[ny][nx] == INF):
            queue.append((nx,ny))
            distance[ny][nx] = distance[y][x] + 1
    
    return distance[gy][gx]

  return bfs()

path = []

for i in range(len(com)):
  s = com[i][0]
  g = com[i][1]
  sx = s[0]
  sy = s[1]
  gx = g[0]
  gy = g[1]
  dist = shortest_path(sx,sy,gx,gy,labyrinth)
  path.append(dist)
  
print(max(path))
