#幅優先探索


from queue import Queue

ans = 0
h,w = map(int, input().split())
maps = [input() for _ in range(h)]
for i in range(h):
  for j in range(w):
    visited = [[-1]*w for _ in range(h)]
    q = Queue()
    q.put([i,j])
    visited[i][j] = 0
    while not q.empty():
      y,x = q.get()
      for k,l in [[1,0],[-1,0],[0,1],[0,-1]]:
        if 0 <= y+k < h and 0<= x+l < w:
            new_y,new_x = y+k,x+l
        else: continue
        if visited[new_y][new_x]== -1 and maps[new_y][new_x]==".":
          visited[new_y][new_x]=visited[y][x]+1
          q.put([new_y,new_x])
        elif visited[new_y][new_x] > visited[y][x]+1:
          visited[new_y][new_x]=visited[y][x]+1
          q.put([new_y,new_x])
          
         
    for ii in range(h):
      for jj in range(w):
        ans = max(ans,visited[ii][jj])
        
print(ans)