H,W=list(map(int,input().split()))
l=[]
import copy
for i in range(H):
   a=list(input())
   a=[-1 if i == "#" else 0 for i in a]
   l.append(a)
from collections import deque
def bfs(x,y,s):
   visited=copy.deepcopy(s)
   visited[x][y] = 1
   que=deque([[x,y]])
   while que:
      node=que.popleft()
      S=visited[node[0]][node[1]]
      try:
         if not visited[node[0]+1][node[1]]:
            visited[node[0]+1][node[1]]=S+1
            que.append([node[0]+1,node[1]])
      except IndexError:
         pass
      try:
         if not visited[node[0]][node[1]+1]:
            visited[node[0]][node[1]+1]=S+1
            que.append([node[0],node[1]+1])
      except IndexError:
         pass
      try:
         if not visited[node[0]][node[1]-1]:
            if node[1]-1 != -1:
               visited[node[0]][node[1]-1]=S+1
               que.append([node[0],node[1]-1])
      except IndexError:
         pass
      try:
         if not visited[node[0]-1][node[1]]:
            if node[0]-1 != -1:
               visited[node[0]-1][node[1]]=S+1
               que.append([node[0]-1,node[1]])
      except IndexError:
         pass
   visited=sum(visited,[])
   return max(visited)-1
ans=0
for i in range(H):
   for j in range(W):
      ans=max(ans,bfs(i,j,l))
print(ans)