ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

h,w = nm()

s = []

for y in range(h):
  s.append([_ for _ in input()])



def bfs(sx,sy,gx,gy,route):
  xx=[1,-1,0,0]
  yy=[0,0,1,-1]
  
  if sx == gx and sy == gy:
    return 0
  
  mn = 9999
  for i in range(4):
    nx = sx + xx[i]
    ny = sy + yy[i]
    
    if 0 <= nx < w and 0 <= ny < h:
      if s[ny][nx] == '.':
        if (nx,ny) not in route:
          mn = min(mn,bfs(nx,ny,gx,gy,route+[(nx,ny)]))
  return mn+1

mx = 0

for sx in range(w):
  for sy in range(h):
    for gx in range(w):
      for gy in range(h):
        if s[sy][sx] == '.' and s[gy][gx] == '.':
          b = bfs(sx,sy,gx,gy,[])
          if b < h*w:
            mx = max(mx,b)

print(mx)