from collections import deque

U, D, L, R = (-1, 0), (+1, 0), (0, -1), (0, +1)

is_good = lambda x, y, R, C: True if x < R and x >= 0 and y < C and y >= 0 else False


def traverse(grid, start, end):
  d = deque([(start, 0)])
  visited = set()
  while d:
    node, path = d.popleft()
    if node == end:
      break
    cx, cy = node
    for dx, dy in U, D, L, R:
      if is_good(cx + dx, cy + dy, len(grid), len(grid[0])) and grid[cx + dx][cy + dy] != '#' and (cx + dx, cy + dy) not in visited:
        nx, ny = cx + dx, cy + dy
        visited.add((nx, ny))
        d.append([(nx, ny), path+1])
  #print(start, end, path)
  return path


def bfs():
  R, C = tuple(map(int, input().split()))
  grid =[list(input()) for _ in range(R)]
  answer = 0
  for row in range(R):
    for col in range(C):
      if grid[row][col] != '#':
        start = (row, col)
      for rw in range(R):
        for cl in range(C):
          if grid[row][col] != '#':
            end = (rw, cl)
            answer = max(answer, traverse(grid, start, end))
  return answer


print(bfs())