from collections import deque

def bfs(start, maze, H, W):
    max_step = 0
    used = [[False for _ in range(W)] for _ in range(H)]
    completed = []
    stack = deque([[start, 0]])
    while stack:
        (i, j), step = stack.popleft()
        used[i][j] = True
        if maze[i][j] == '#':
            continue
        max_step = max(max_step, step)
        is_proceeding = False
        for x, y in [(i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)]:
            if 0 <= x < H and 0 <= y < W and not used[x][y]:
                stack.append([(x, y), step + 1])
                is_proceeding = True
        if is_proceeding:
            completed.append([i, j])
    return max_step, completed

if __name__ == '__main__':
    H, W = map(int, input().split())
    S = []
    for _ in range(H):
        S.append(list(input()))
    ret = 0
    used = [[False for _ in range(W)] for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if used[i][j]:
                continue
            step, completed = bfs((i, j), S, H, W)
            ret = max(ret, step)
            for x, y in completed:
                used[x][y] = True
    print(ret)