from collections import deque
H,W = map(int,input().split())
S= [[0]* W for _ in range(H)]
d= [[-1 for _ in range (W)] for _ in range(H)]
for i in range(H):
  S[i] = list("".join(input()))


def BFS(i,j):
  v= deque([[i,j]])
  d[i][j]=0
  
  while len(v)>0:
    a=v.popleft()
    s=a[0]
    t=a[1]
    if s>0:
      if d[s-1][t]==-1 and S[s-1][t]==".":
        d[s-1][t]= d[s][t]+1
        v.append([s-1,t])
    if s<H-1:
      if d[s+1][t]==-1 and S[s+1][t]==".":
        d[s+1][t]= d[s][t]+1
        v.append([s+1,t])
    if t>0:
      if d[s][t-1]==-1 and S[s][t-1]==".":
        d[s][t-1]= d[s][t]+1
        v.append([s,t-1])
    if t<W-1:
      if d[s][t+1]==-1 and S[s][t+1]==".":
        d[s][t+1]= d[s][t]+1
        v.append([s,t+1])
  maxi=0
  for y in d:
    for x in y:
      maxi=max(maxi,x)
  return maxi

ans=0
for j in range(H):
  for j in range(W):
    ans=max(ans,BFS(i,j))
print(ans)