from collections import defaultdict

H, W = map(int, input().split())

maze = []
for _ in range(H):
  maze.append([i for i in input()])
  
# 無向グラフを作ってワーシャルフロイド法で解く

inf = float("inf")
d = defaultdict(lambda: inf)

directions = [(1, 0), (0, 1)]
for i in range(H):
  for j in range(W):
    if maze[i][j] == '.':
      d[((i, j), (i, j))] = 0
      for di, dj in directions:
        if i + di < H and j + dj < W\
        and maze[i + di][j + dj] == '.':
          d[((i, j), (i + di, j + dj))] = 1
          d[((i + di, j + dj), (i, j))] = 1

for i1 in range(H):
  for j1 in range(W):
    if maze[i1][j1] == '.':
      for i2 in range(H):
        for j2 in range(W):
          if maze[i2][j2] == '.':
            for i3 in range(H):
              for j3 in range(W):
                if maze[i3][j3] == '.':
                  d[((i1, j1), (i3, j3))]\
                  = min(
                    d[((i1, j1), (i3, j3))],
                    d[((i1, j1), (i2, j2))] + d[((i2, j2), (i3, j3))]
                  )

# 全ての連結成分の最大距離を求めて出力

ret = 0
for value in d.values():
  if value != inf:
    ret = max(ret, value)
    
print(ret)