import sys
from collections import deque as dq
input = sys.stdin.readline
H, W = map(int, input().split())
maze = [list(input())[: -1] for _ in range(H)]
#print(maze)
res = 0
d = [-1, 0, 1, 0]
for s in range(H * W):
  sy = s // W
  sx = s % W
  Q = dq([])
  Q.append(s)
  dist = [float("inf")] * (H * W)
  dist[s] = 0
  while len(Q):
    p = Q.popleft()
    py = p // W
    px = p % W
    for k in range(4):
      qy = py + d[k]
      qx = px + d[-1 - k]
      if 0 <= qy < H and (0 <= qx < W):
        if maze[qy][qx] == "#": continue
        if dist[qy * W + qx] > dist[p] + 1:
          Q.append(qy * W + qx)
          dist[qy * W + qx] = dist[p] + 1
  for x in dist:
    if x != float("inf"): res = max(res, x)
print(res)