import queue
import copy

INF = 10 ** 10

H, W = map(int, input().split())

maze = [[-1] * (W+2)]
for _ in range(H):
    maze.append( [-1] + list( map(lambda c: INF if c == '.' else -1, input()) ) + [-1] )
maze.append([-1] * (W+2))

maze_backup = copy.deepcopy(maze)
maxpath = 0
for start_y in range(1, H+1):
    for start_x in range(1, W+1):
        if maze[start_y][start_x] == -1:
            continue
        
        counter = 0
        mincounter = 2
        for dy, dx in ((-1, 0), (1, 0), (0, 1), (0, -1)):
            if maze[start_y+dy][start_x+dx] == INF:
                counter += 1
        if counter > mincounter:
            break
        else:
            mincounter = counter

        bfs_q = queue.Queue()
        bfs_q.put( (start_y, start_x) )
        maze[start_y][start_x] = 0

        while not bfs_q.empty():
            y, x = bfs_q.get()
            for dy, dx in ((-1, 0), (1, 0), (0, 1), (0, -1)):
                if maze[y+dy][x+dx] > maze[y][x] + 1:
                    maze[y+dy][x+dx] = maze[y][x] + 1
                    bfs_q.put( (y+dy, x+dx) )

        maxpath = max(maxpath, max(max(row) for row in maze))
        maze = copy.deepcopy(maze_backup)

print(maxpath)