from queue import Queue
dx = [0, 1, 0, -1]
dy = [-1, 0, 1, 0]
def main():
    h, w = [int(x) for x in input().split()]
    grid = []

    for _ in range(h):
        linha = [x for x in input()]
        grid.append(linha)

    resp = 0
    for i in range(h):
        for j in range(w):
            if grid[i][j] == '.':
                resp = max(resp, BFS(i, j, grid, h, w, [[False]*w for _ in range(h)]))

    print(resp)
    
def BFS(x, y, grafo, h, w, passou):

    fila = Queue()
    fila.put((0, x, y))
    
    while not fila.empty():
        c, x, y = fila.get()

        for i in range(4):
            if 0 <= x + dx[i] < h and 0 <= y + dy[i] < w and grafo[x + dx[i]][y + dy[i]] == '.' and not passou[x + dx[i]][y + dy[i]]:
                fila.put((c + 1, x + dx[i], y + dy[i]))
                passou[x + dx[i]][y + dy[i]] = True
                
    return c

main()