from collections import deque

H,W=map(int,input().split())
MAP=[list(input()) for y in range(H)]

def Maze(_x, _y):
  MAP2=[[-1 for x in range(W)] for y in range(H)]
  for y in range(H):
    for x in range(W):
      if MAP[y][x]=='#':
        MAP2[y][x]=-2
  q=deque([[_x,_y]])
  MAP2[_y][_x]=0
  while q:
    xy=q.popleft()
    for d in [(0,-1),(-1,0),(0,1),(1,0)]:
      x2,y2=xy[0]+d[0],xy[1]+d[1]
      if x2<0 or y2<0 or x2>=W or y2>=H:
        continue
      if MAP2[y2][x2]==-1:
        q.append([x2,y2])
        MAP2[y2][x2]=MAP2[xy[1]][xy[0]]+1
  
  maxM=0
  for y in range(H):
    for x in range(W):
      maxM=max(maxM, MAP2[y][x])
  return maxM
  
  
ans=0
for y in range(H):
  for x in range(W):
    ans=max(ans, Maze(x,y))
print(ans)