H, W = map(int, input().split())
atlas = []
for i in range(H):
  atlas.append(input().split())

def BFS(a,b):
  times = 0
  queue = [[a, b]]
  old_queue = []
  while True:
    new_queue = []
    changed = False
    for x, y in queue:
      if x+1 < H and atlas[x+1][y] != "#" and not [x+1, y] in old_queue:
        new_queue.append([x+1, y])
        old_queue.append([x+1, y])
        changed = True
      if x-1 >= 0 and atlas[x-1][y] != "#" and not [x-1, y] in old_queue:
        new_queue.append([x-1, y])
        old_queue.append([x-1, y])
        changed = True
      if y+1 < W and atlas[x][y+1] != "#" and not [x, y+1] in old_queue:
        new_queue.append([x, y+1])
        old_queue.append([x, y+1])
        changed = True
      if y-1 >= 0 and atlas[x][y-1] != "#" and not [x, y-1] in old_queue:
        new_queue.append([x, y-1])
        old_queue.append([x, y-1])
        changed = True
    queue = new_queue
    if not changed:
      break
    times += 1
  return times

TIMES = 0
for j in range(H):
  for k in range(W):
    if atlas[j][k] == "#":
      break
    new_TIMES = BFS(j, k)
    if new_TIMES > TIMES:
      TIMES = new_TIMES
      
print(TIMES)