import queue
import copy
import itertools
r,c=map(int,input().split())
r += 2
c += 2
row = r
col = c
maze = [None for _ in range(r)]
maze[0] = ['#' for _ in range(c)]
maze[r - 1] = ['#' for _ in range(c)]
for i in range(1, r - 1):
  maze[i] = ['#'] + list(input()) + ['#']

PATH = '.'
WALL = '#'
UP = [1, 0]
DOWN = [-1, 0]
RIGHT = [0, 1]
LEFT = [0, -1]

list_r = [int(i) for i in range(1, r - 1)]
list_c = [int(i) for i in range(1, c - 1)]
zahyo = list(itertools.product(list_r, list_c))
sgs = list(itertools.product(zahyo, zahyo))

max_dis = 0
for sg in sgs:
  start_y, start_x = sg[0]
  goal_y, goal_x = sg[1]
  if start_y == goal_y and start_x == goal_x:
    continue
  if maze[start_y][start_x] == '#' or maze[goal_y][goal_x] == '#':
    continue

  GOAL = [goal_y, goal_x]
  queue = []
  distance = [[-1]*col for _ in range(row)]
  distance[start_y][start_x] = 0
  queue.append([start_y, start_x])
  while queue:
      current_y, current_x = queue.pop(0)
      if [current_y, current_x] == GOAL:
          dis = distance[current_y][current_x]
          if max_dis < dis:
            max_dis = dis
          # print(distance[current_y][current_x])
          break
          
      for y, x in [UP, DOWN, RIGHT, LEFT]:
          next_y, next_x = current_y + y, current_x + x
          if maze[next_y][next_x] == PATH and \
              distance[next_y][next_x] < 0:
              queue.append([next_y, next_x])
              distance[next_y][next_x] = distance[current_y][current_x] + 1
  # print('could not reach the goal')

print(max_dis)