from collections import deque

H,W=map(int,input().split())
S=[input() for _ in range(H)]

ans=[]
for i in range(H):
  for j in range(W):
    if S[i][j]=="#":
      continue
    queue=deque([[i,j]])
    visited=[[-1]*W for _ in range(H)]
    visited[i][j]=0
    while queue:
      y,x=queue.popleft()
      for k,l in ([1,0], [-1,0], [0,1], [0,-1]):
        new_y,new_x=y+k,x+l
        if new_y<0 or new_x<0 or new_y>=H or new_x>=W:
          continue
        elif S[new_y][new_x]=="." and visited[new_y][new_x]==-1:
          visited[new_y][new_x]=visited[y][x]+1
          queue.append([new_y,new_x])
    L=0
    for m in range(H):
      val=max(visited[m])
      L=max(L,val)
    ans.append(L)
print(max(ans))