H,W = map(int, input().split(' '))
mass = []

mass.append(['#']*(W+2))
for i in range(H):
  mass.append(['#'] + [ x for x in input()] + ['#'])
mass.append(['#']*(W+2))

def find_next(mass, x, y):
  return [ (p,q) for p,q in [(x + 1, y),(x - 1, y), (x, y + 1),(x, y - 1)] if mass[p][q] == '.' ] 
  

def find_all(mass):
  for i in range(1,H+1):
    for j in range(1,W+1):
      if mass[i][j] == '.':
        yield (i,j)

def search(mass, x,y, tx, ty):
  open_list = []
  closed_list = set()
 
  open_list.append((x,y,0))
  min_level = -1 
 
  while len(open_list) > 0:
    sx, sy, level = open_list.pop(0)
    closed_list.add((sx, sy))
    if sx == tx and sy == ty:
      if min_level == -1:
         min_level = level
      elif min_level > level:
         min_level = level
      continue
    nexts = find_next(mass, sx, sy)
    for x in nexts:
      if x not in closed_list:
        open_list.append((x[0], x[1], level+1))
  return min_level


#print(search(mass, 1, 3, 3, 3))
#exit(0)
M = [ x for x in find_all(mass)]
min = 0
for x in M:
  for y in M:
    if y[0] == x[0] and y[1] == x[1]:
      continue
    r = search(mass, x[0], x[1], y[0], y[1])
    if r > min:
      min = r

print(min) 