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
  for g in range(H * W):
    gy = g // W
    gx = g % 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
    if dist[g] != float("inf"): res = max(res, dist[g])
print(res)