import sys
sys.setrecursionlimit(1000000)
from queue import Queue
h,w=map(int,input().split())
S=[input() for _ in range(h)]

def bfs(q,memo):
  x,y,cnt=q.get()
  if x<0 or x>=w or y<0 or y>=h:
    return
  elif S[y][x]=='#':
    return
  elif memo[y][x]<0:
    memo[y][x]=cnt
    q.put([x-1,y,cnt+1])
    q.put([x+1,y,cnt+1])
    q.put([x,y-1,cnt+1])
    q.put([x,y+1,cnt+1])
    
ans=0
out=[]
def bbfs(x,y,ans):
  q=Queue()
  q.put([x,y,0])

  memo=[[-1]*w for _ in range(h)]
  while not q.empty():
    bfs(q,memo)
  if max(max(memo))>=ans:
    ans=max(max(memo))
    bbfs(x-1,y,ans)
    bbfs(x+1,y,ans)
    bbfs(x,y-1,ans)
    bbfs(x,y+1,ans)
    if ans!=None: out.append(ans)
    
bbfs(0,0,ans)
print(max(out))