from collections import defaultdict
from copy import copy
from queue import Queue

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)
for i in range(H):
  for j in range(W):
    if maze[i][j] == '.':
      d[((i, j), (i, j))] = 0

directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for i in range(H):
  for j in range(W):
    if maze[i][j] == '.':
      for di, dj in directions:
        if i + di >= 0 and i + di < H\
        and j + dj >= 0 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):
    for i2 in range(H):
      for j2 in range(W):
        for i3 in range(H):
          for j3 in range(W):
            if maze[i1][j1] == '.'\
            and maze[i2][j2] == '.'\
            and 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 i1 in range(H):
  for j1 in range(W):
    for i2 in range(H):
      for j2 in range(W):
        if d[((i1, j1), (i2, j2))] != inf\
        and d[((i1, j1), (i2, j2))] > ret:
          ret = d[((i1, j1), (i2, j2))]
          
print(ret)