import copy
import queue
from itertools import combinations

def cal(s, g, f_org):
  f = copy.deepcopy(f_org)
  m = [(1, 0), (0, 1), (-1, 0), (0, -1)]
  q = queue.Queue()
  q.put(s)
  while not q.empty():
    x, y, t = q.get()
    if (x == g[0]) and (y == g[1]):
      break
    for i, j in m:
      if f[y+i][x+j] == '.':
        q.put((x+j, y+i, t+1))
        f[y+i][x+j] = '#'
  return t

def run():
  H, W = map(int, input().split())
  f = [['#']*(W+2)]
  f += [list('#'+input()+'#') for _ in range(H)]
  f += [['#']*(W+2)]
  t_li = []
  po_li = []
  for x in range(1, W+1):
    for y in range(1, H+1):
      po_li.append((x, y))
  for (sx, sy), (gx, gy) in combinations(po_li, 2):
    if f[sy][sx] == '#' or f[gy][gx] == '#':
      continue
    t = cal((sx, sy, 0), (gx, gy), f)
    #print(sx, sy, gx, gy, t)
    t_li.append(t)
  #print(t_li)
  print(max(t_li))

if __name__ == '__main__':
  run()