H, W = map(int,input().split())
grid = [list(input().split()) for _ in H]
res = 0
def bfs(tup,visited):
  def helper(tup, total):
    if tup in visited():
      res = max(res, total)
    elif tup[0]>=H or tup[0] < 0 or tup[1]>=W or tup[1]<0 or grid[tup[0]][tup[1]]:
      res = max(res, total)
    else:
      visited.add(tup)
      h, w = tup
      helper((h+1, w),total+1)
      helper((h-1, w),total+1)
      helper((h, w-1),total+1)
      helper((h, w+1),total+1)
  helper(tup,0)
  return res
      
ans = 0
for h in H:
  for w in W:
    if grid[h][w] == '#':
      continue
    ans = max(ans,bfs((h,w),set()))
print(ans)