from collections import deque

h,w=map(int,input().split())
l=[input() for _ in range(h)]

ma=0
dx=[1,0,-1,0]
dy=[0,1,0,-1]

def bfs(sx,sy):
    if l[sy][sx]=="#":
      return 0
    
    d=[[float("inf")]*w for i in range(h)]
    
    que=deque([])
    que.append((sx,sy))
    d[sy][sx]=0

    while que:
      p = que.popleft()
 
      for i in range(4):
          nx=p[0]+dx[i]
          ny=p[1]+dy[i]

          if 0<=nx<w and 0<=ny<h and l[ny][nx] != "#" and d[ny][nx] == float("inf"):
              que.append((nx,ny))
              d[ny][nx] = d[p[1]][p[0]] + 1
              gx=nx
              gy=ny
 
    return d[gy][gx]

for i in range(h):
  for k in range(w):
    ma = max(ma,bfs(k,i))
    
print(ma)