import queue
h, w = map(int, input().split())
m = []
for i in range(h):
  m.append(input())
#print(h, w)
#print(m)
q = queue.Queue()
a = []
def init():
  global a, q
  q = queue.Queue()
  a = []
  for i in range(h):
    a.append([-1] * w)

def bfs(cx, cy):
  nxs = [1, 0, -1, 0]
  nys = [0, -1, 0, 1]
  for i in range(4):
    nx = cx + nxs[i]
    ny = cy + nys[i]
    if 0 <= nx and nx < w and 0 <= ny and ny < h and m[ny][nx] == '.' and a[ny][nx] == -1:
      a[ny][nx] = a[cy][cx] + 1
      q.put([nx, ny])
  
def check(start_x, start_y, end_x, end_y):
  if m[start_y][start_x] == '#' or m[end_y][end_x] == '#':
    return 0
  if start_x == end_x and start_y == end_y:
    return 0
  
  global a, q
  init()
  q.put([start_x, start_y])
  a[start_y][start_x] = 0
  while not q.empty():
    cx, cy = q.get()
    bfs(cx, cy)
  return a[end_y][end_x]

ans = 0
#for start_y in range(h):
#  for start_x in range(w):
#    for end_y in range(h):
#      for end_x in range(w):
#        ans = max(ans, check(start_x, start_y, end_x, end_y))
for i in range(h * w - 1):
  for j in range(i+1, h * w):
    start_x = i % w
    start_y = i // w
    end_x = j % w
    end_y = j // w
    #print(start_x, start_y, end_x, end_y)
    ans = max(ans, check(start_x, start_y, end_x, end_y))
    
print(ans)