from collections import deque
H, W = map(int, input().split())
H += 2
W += 2
maze = '#' * W
for _ in range(H-2):
  maze += '#' + input() + '#'
maze += '#' * W
 
def bfs(root):
  if maze[root] == '#':
    return -1
  dist = [-1] * (H*W)
  dist[root] = 0
  q = deque([root])
  while q:
    x = q.popleft()
    for d in [1, -1, W, -W]:
      if maze[x+d] == '.' and dist[x+d] == -1:
        q.append(x+d)
        dist[x+d] = dist[x] + 1
  return max(dist)
 
ans = max(bfs(i) for i in range(H*W))
print(ans)