from collections import deque
from scipy.sparse.csgraph import floyd_warshall

def solve():
  h,w = (int(i) for i in input().split())
  maze = ["#"*(w+2)]
  for i in range(h):
    maze.append("#" + input() + "#")
  maze.append("#"*(w+2))

  dist = [(1,0),(0,1),(-1,0),(0,-1)]
  d = [[0]*500 for _ in range(500)]
  for y in range(1,h+1):
    for x in range(1,w+1):
      if maze[y][x] == ".":
        for dy,dx in dist:
          if maze[y+dy][x+dx] == ".":
            oldy = x + w*y
            inty = x+dx + w*(y+dy)
            d[inty][oldy] = 1
            d[oldy][inty] = 1
  ans = 0
  d = floyd_warshall(d)
  for i in range(500):
    for j in range(500):
      if d[i][j] < 10**15:
              ans = max(d[i][j],ans)
  print(int(ans))




solve()