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