n, m = map(int, input().split())
grid = [input() for i in range(n)]

res = 0
dirs = [(0,1),(1,0),(0,-1),(-1,0)]

for a in range(n):
  for b in range(m):
    if grid[a][b] != '.':
      continue
    vis = set([(a,b)])
    q = [(a,b,0)]
    qi = 0
    while qi < len(q):
      i, j, c = q[qi]
      res = max(res, c)
      qi += 1
      for di, dj in dirs:
        ni, nj = i + di, j + dj
        if (ni, nj) in vis or ni < 0 or ni >= n or nj < 0 or nj >= m or grid[ni][nj] != '.':
          continue
        vis.add((ni, nj))
        q.append((ni, nj, c+1))
print(res)
    
