from collections import deque
import sys
sys.setrecursionlimit(10**8)
INF = float('inf')



h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]

def bfs(sy, sx):
  dist = [[0 for x in range(w)] for y in range(h)]
  dy = [0, 1, 0, -1]
  dx = [1, 0, -1, 0]
  Q = deque()
  Q.append((sy, sx))
  while Q:
    q = Q.popleft()
    y = q[0]
    x = q[1]
    d = dist[y][x]
    for i in range(4):
      ny = y + dy[i]
      nx = x + dx[i]
      if ny < 0 or h <= ny or nx < 0 or w <= nx:
        continue
      #迷路における道が'.'、壁が'#'で表されている場合
      if maze[ny][nx] == '#':
        continue
      nd = d + 1
      if dist[ny][nx] != 0 and nd >= dist[ny][nx]:
        continue
      dist[ny][nx] = nd
      Q.append((ny, nx))
  return max(max(x) for x in dist)

ans = 0
for y in range(h):
  for x in range(w):
    if maze[y][x] == '.':
      ans = max(ans, bfs(y,x))
print(ans)