def visit(maze, state, i, j):
  #maze: 迷路 (H, W)
  #state 各マスに、Sの位置からの最小値が格納された状態 (H, W)
  if i>0 and maze[i-1][j]=="." and state[i-1][j]>=state[i][j]+1:
    state[i-1][j]=state[i][j]+1
    state=visit(maze, state, i-1, j)
  if i<H-1 and maze[i+1][j]=="." and state[i+1][j]>=state[i][j]+1:
    state[i+1][j]=state[i][j]+1
    state=visit(maze, state, i+1, j)
  if j>0 and maze[i][j-1]=="." and state[i][j-1]>=state[i][j]+1:
    state[i][j-1]=state[i][j]+1
    state=visit(maze, state, i, j-1)
  if j<W-1 and maze[i][j+1]=="." and state[i][j+1]>=state[i][j]+1:
    state[i][j+1]=state[i][j]+1
    state=visit(maze, state, i, j+1)
  return state

H, W=map(int, input().split())
S=[input() for _ in range(H)]
ans=0
for i in range(H):
  for j in range(W):
    state=[[1000 for _ in range(W)] for _ in range(H)]
    state[i][j]=0
    state=visit(S, state, i, j)
    for i in range(H):
      for j in range(W):
        if state[i][j]==1000:
          state[i][j]=0
    for i in range(H):
      ans=max(ans, max(state[i]))
print(ans)