import sys
sys.setrecursionlimit(10000000)
H,W=map(int,input().split())
field=[input() for _ in range(H)]

def dfs(d,x,y,gx,gy,seen):
  global dist
  if x==gx and y==gy:
    dist=min(dist,d)
  else:
    if x>=W or x<0 or y>=H or y<0:
      pass
    elif field[y][x]=="#":
      pass
    else:
      dx=[1,0,-1,0]
      dy=[0,1,0,-1]
      for i in range(4):
        if [x+dx[i],y+dy[i]] not in seen:
          seen.append([x+dx[i],y+dy[i]])
          dfs(d+1,x+dx[i],y+dy[i],gx,gy,seen)
          seen.remove([x+dx[i],y+dy[i]])

ans=-1
for i in range(H):
  for j in range(W):
    if field[i][j]=="#":
      pass
    else:
      for k in range(H):
        for l in range(W):
          if field[k][l]=="#":
            pass
          if k==i and l==j:
            pass
          else:
            dist=float("inf")
            dfs(0,j,i,l,k,[[j,i]])
            ans=max(ans,dist)
        
print(ans)      