from collections import deque

q = deque()

H, W = map(int, input().split())
m = [list(input()) for i in range(H)]

for h in range(H):
  for w in range(W):
    if m[h][w] == ".":
      q.append((h, w))

d = {}
for h in range(H):
  for w in range(W):
    d[(h, w)] = {}

while q:
  h, w = q.pop()
  if 0 <= h-1 and m[h-1][w] == ".":
    q.append((h-1, w))
    d[(h, w)][(h-1, w)] = 1
    d[(h-1, w)][(h, w)] = 1
  if h+1 < H  and m[h+1][w] == ".":
    q.append((h+1, w))
    d[(h, w)][(h+1, w)] = 1
    d[(h+1, w)][(h, w)] = 1
  if 0 <= w-1 and m[h][w-1] == ".":
    q.append((h, w-1))
    d[(h, w)][(h, w-1)] = 1
    d[(h, w-1)][(h, w)] = 1
  if w+1 < W  and m[h][w+1] == ".":
    q.append((h, w+1))
    d[(h, w)][(h, w+1)] = 1
    d[(h, w+1)][(h, w)] = 1
  
  m[h][w] = "#"

for it in range(H*W):
  for jt in range(H*W):
    for kt in range(H*W):
      i = divmod(it, W)
      j = divmod(jt, W)
      k = divmod(kt, W)
      d[j][k] = min(d[j].get(k, float("inf")), d[j].get(i, float("inf")) + d[k].get(i, float("inf")))

maxd = 0
for s in d.values():
  for g in s.values():
    if g <= H*W:
      maxd = max(g, maxd)
print(maxd)