import queue

h, w = map(int, input().split())
maze = [[(False, False, False, False) for _ in range(w)] for _ in range(h)]
inputs = [list(map(lambda x: x == "#", input())) for _ in range(h)]

def bfs(x, y):
    q = queue.Queue()
    visited = [[False for _ in range(w)] for _ in range(h)]
    visited[x][y] = True
    q.put((x, y, 0))

    max_length = 0

    while not q.empty():
        vx, vy, length = q.get()
        max_length = max(max_length, length)
        (ue, migi, hidari, shita) = maze[vx][vy]
        if not ue:
            if not visited[vx - 1][vy]:
                visited[vx - 1][vy] = True
                q.put((vx - 1, vy, length + 1))
        if not migi:
            if not visited[vx][vy + 1]:
                visited[vx][vy + 1] = True
                q.put((vx, vy + 1, length + 1))
        if not hidari:
            if not visited[vx][vy - 1]:
                visited[vx][vy - 1] = True
                q.put((vx, vy - 1, length + 1))
        if not shita:
            if not visited[vx + 1][vy]:
                visited[vx + 1][vy] = True
                q.put((vx + 1, vy, length + 1))
    
    return max_length

for x in range(h):
    for y in range(w):
        ue = (x == 0) or inputs[x - 1][y]
        migi = (y == w - 1) or inputs[x][y + 1]
        hidari = (y == 0) or inputs[x][y - 1]
        shita = (x == h - 1) or inputs[x + 1][y]

        maze[x][y] = (ue, migi, hidari, shita)

result = 0

for x in range(h):
    for y in range(w):
        point = maze[x][y]
        if sum(point) >= 3:
            pass
        result = max(result, bfs(x, y))

print(result)
