import queue
h, w = map(int, input().split())
bigger = h if h > w else w
dfs = [[0]*bigger]*bigger
used_dfs = [[[]]*bigger]*bigger
q = queue.Queue
d = []
for i in range(h):
  s = [j for j in input()]
  d.append(s)
from collections import defaultdict
def find_possible(i, j):
  if i >= h-1:
    iaround = [i, i-1]
  elif i<=0:
    iaround = [i, i+1]
  else:
    iaround = [i, i-1, i+1]
  if j >= w-1:
    jaround = [j, j-1]
  elif j<=0:
    jaround = [j, j+1]
  else:
    jaround = [j, j-1, j+1]
  retv = []
  for a1 in iaround:
    for a2 in jaround:
      if abs(a1-i) == abs(a2-j):
        continue
      elif d[a1][a2] == '.':
        retv.append([a1, a2])
  #print(i,j,retv)
  return retv

def bfs(qu):
  #includes points=[y][x], distance, parents=[[y][x]]
  used = [[-1 for _ in range(w)] for _ in range(h)]
  m = 0
  while not qu.empty():
    current = qu.get()
    row = current[0][0]
    column = current[0][1]
#    print(row, column, used[row][column])
    if used[row][column] > current[1] or used[row][column]<0:
      used[row][column] = current[1]
#      print(used)
#      print('update:', current[1])
      for a in find_possible(row, column):
        if (a not in current[2]) and (a != [row, column]):
          tmp = current[2] + [[row, column]]
#          print('extend:',a,current[1]+1, tmp)          
          qu.put([a,current[1]+1, tmp])
   #       if current[1]+1 > m:
   #         m = current[1]+1
#    print()
  m = 0
  for row in used:
    for column in row:
      if column == -1:
        continue
      elif m < column:
        m = column
  return m
m = 0
for i in range(h):
  for j in range(w):
    q = queue.Queue()
    q.put([[i,j], 0, []])
    t = bfs(q)
    if m < t:
      m = t
print(m)