from collections import deque
H, W = map(int, input().split())
X = [input() for _ in range(H)]
maxloc = -10

def bfs(sx, sy, gx, gy):
  dist = [[-1]*W for _ in range(H)]
  dist[sx-1][sy-1] = 0
  q = deque([(sx-1, sy-1)])
  while q:
    u, v = q.popleft()
    for i, j in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
      if not(0 <= u+i < H and 0 <= v+j < W):
        continue
    
      if(dist[u+i][v+j] >= 0 or X[u+i][v+j] == "#"):
        continue

      dist[u+i][v+j] = dist[u][v]+1
      q.append((u+i, v+j))

  return dist[gx-1][gy-1]

for i in range(H):
  for j in range(W):
    sx = i
    sy = j
    for k in range(H):
      for l in range(W):
        gx = k
        gy = l
        if(bfs(i+1, j+1, k+1, l+1) > maxloc):
          maxloc = bfs(i+1, j+1, k+1, l+1)
          
print(maxloc)