from collections import deque
h,w = map(int, input().split())
maze = [list(input()) for i in range(h)]


def bfs(maze, sx, sy, gy, gx):
    d = [[float("inf")] * w for i in range(h)]

    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque([])
    que.append((sy, sx))
    d[sy][sx] = 0

    while que:
        p = que.popleft()
        if p[0] == gy and p[1] == gx:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and d[nx][ny] == float("inf"):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1

    return d[gy][gx]


ans = 0
for i in range(h):
    for j in range(w):
        if maze[i][j]!="#":
            for k in range(i,h):
                for l in range(j,w):
                    if maze[k][l]!="#":
                        ans = max(ans, bfs(maze, j, i, l, k))

print(ans)
