from copy import deepcopy
H, W = map(int, input().split())
spots = []
dirs = [[0, 1], [1, 0], [0, -1], [-1, 0]]
maze = []
for h in range(H):
  line = list(input())
  maze.append(line)
res = 0

for h in range(H):
  for w in range(W):
    if maze[h][w] == '.':
      newMaze = deepcopy(maze)
      # print(j, i)
      # for line in newMaze:
      #   print(line)
      # print()
      newSpots = [[h, w]]
      count = 0
      while True:
        spots = newSpots
        newSpots = []
        # print(count)
        # for line in newMaze:
        #   print(line)
        # print()
        if 0 < len(spots):
          count += 1
        else:
          break
        for pos in spots:
          newMaze[pos[0]][pos[1]] = '#'
          if res < count:
            res = count
          # if j == 5 and i == 4:
          #   for line in newMaze:
          #     print(line)
          #   print()
          for d in dirs:
            x = d[1] + pos[1]
            y = d[0] + pos[0]
            if 0 <= x < W and 0 <= y < H and newMaze[y][x] == '.':
              nextPos = newMaze[y][x]
              newSpots.append([y, x])
      if res < count:
        res = count
print(res-1)