H,W = map(int,input().split())
Gd = [list(input()) for _ in range(H)]
INF = -1
direc = [[1,0,-1,0],[0,1,0,-1]]
from collections import deque
def dfs(start):
  q = deque([])# スタック
  Dis[start[0]][start[1]]=0
  q.append(start)
  while len(q)!=0:
    h,w = q.popleft()# スタック取りだし（先頭）
    for i in range(4):
      hs = h+direc[0][i]
      ws = w+direc[1][i]
      if 0<=hs<H and 0<=ws<W and Dis[hs][ws]==INF:
        if Gd[hs][ws]=='.':
          q.append([hs,ws])
          Dis[hs][ws]=Dis[h][w]+1
  return max(max(Dis))
Dis = [[INF]*W for _ in range(H)]
ans = INF
for h in range(H):
  for w in range(W):
    if Gd[h][w]=='.':
      Dis = [[INF]*W for _ in range(H)]
      start = [h,w]
      ans = max(ans,dfs(start))
print(ans)