
h,w=map(int,input().split())
g=[input() for _ in range(h)]
def search(y,x):
  que=[(y,x)]
  vis=[[-1]*w for _ in range(h)]
  vis[y][x]=0
  while que:
    cy,cx=que.pop(0)
    for dy,dx in ((1,0),(-1,0),(0,1),(0,-1)):
      ny,nx=cy+dy,cx+dx
      if 0<=ny<h and 0<=nx<w and g[ny][nx]=="." and vis[ny][nx]==-1:
        vis[ny][nx]=vis[cy][cx]+1
        que.append((ny,nx))
  return max(max(l) for l in vis)
ans=0
for i in range(h):
  for j in range(w):
    if g[i][j]==".":
      ans=max(search(i,j),ans)
print(ans)