H,W=map(int,input().split())

def warshall_floyd(vl,d):
  #d[vi][vj]: viからvjへの最短距離
  for vk in vl:
    for vi in vl:
      for vj in vl:
        if vk in d[vi] and vj in d[vk]:
          if not vj in d[vi]:
            d[vi][vj]=d[vi][vk]+d[vk][vj]
          else:
            d[vi][vj]=min(d[vi][vj],d[vi][vk]+d[vk][vj])
  return d

# vlistに点のリスト、dist[vi][vj]に辺(vi,vj)のコストを入れて呼び出す
mat=[[x=="." for x in input()] for _ in range(H)]
#print(mat)

vlist=[]
dist={}
for i in range(H):
  for j in range(W):
    if mat[i][j]:
      vlist.append((i,j))
      if not (i,j) in dist:
        dist[(i,j)]={}
      dist[(i,j)][(i,j)]=0
      if i>0 and mat[i-1][j]:
          dist[(i,j)][(i-1,j)]=1
      if i<H-1 and mat[i+1][j]:
          dist[(i,j)][(i+1,j)]=1
      if j>0 and mat[i][j-1]:
          dist[(i,j)][(i,j-1)]=1
      if j<W-1 and mat[i][j+1]:
          dist[(i,j)][(i,j+1)]=1

#print(vlist)
#print(dist)
dist=warshall_floyd(vlist,dist)
#print(dist)
answer=0
for x in dist:
  for y in dist[x]:
    answer=max(answer,dist[x][y])
    
print(answer)