from collections import deque

H, W = map(int, input().split())
S = [input() for _ in range(H)]

INF = 10**15
d = [(1, 0), (-1, 0), (0, 1), (0, -1)]

answer = 0
for i in range(H):
  for j in range(W):
    if S[i][j] == "#":
      continue
    else:
      dist = [[INF for _ in range(W)] for _ in range(H)]
      dist[i][j] = 0
      stack = deque([(i, j)])
      
      while stack:
        s = stack.popleft()
        si, sj = s
        for di, dj in d:
          if 0 <= si + di <= H - 1 and 0 <= sj + dj <= W - 1 and S[si + di][sj + dj] != "#":
            if dist[si + di][sj + dj] > dist[si][sj] + 1:
              dist[si + di][sj + dj] = dist[si][sj] + 1
              stack.append((si + di, sj + dj))
      #print(dist)

      max_dist = 0
      for i in range(H):
        for j in range(W):
          if dist[i][j] != INF:
            max_dist = max(max_dist, dist[i][j])
      answer = max(max_dist, answer)
      
print(answer)