h, w = map(int, input().split())
s = ['#'*(w+2)]
for i in range(h):
  s.append('#'+input()+'#')
s.append(['#'*(w+2)])

import queue

def search(x, y):
  p = [[-1]*(w+2) for _ in range(h+2)]
  q = queue.Queue()
  q.put([x,y,0])
  p[x][y] = 0
  
  while not q.empty():
    ijt = q.get()
    i = ijt[0]
    j = ijt[1]
    t = ijt[2]
    p[i][j] = t
    if i != 1:
      if s[i-1][j] != '#' and p[i-1][j] == -1:
        q.put([i-1,j,t+1])
    if i != h:
      if s[i+1][j] != '#' and p[i+1][j] == -1:
        q.put([i+1,j,t+1])
    if j != 1:
      if s[i][j-1] != '#' and p[i][j-1] == -1:
        q.put([i,j-1,t+1])
    if j != w:
      if s[i][j+1] != '#' and p[i][j+1] == -1:
        q.put([i,j+1,t+1])
  v = max([max(p[_]) for _ in range(len(p))])
  return v
    
  
ans = 0
for i in range(1,h+1):
  for j in range(1,w+1):
    if s[i][j] == '.':
      v = search(i,j)
      ans = max(ans, v)
print(ans)