from collections import deque
def dfs(maze,sx,sy):
    q = deque([(sx, sy, 0)])
    visited = [[False] * w for _ in range(h)]
    while q:
        i, j, d = q.popleft()
        if visited[i][j]:
            continue
        visited[i][j] = True
        if i > 0 and maze[i-1][j] == '.':
            q.append((i-1, j, d+1))
        if i < h - 1 and maze[i+1][j] == '.':
            q.append((i+1, j, d+1))
        if j > 0 and maze[i][j-1] == '.':
            q.append((i, j-1, d+1))
        if j < w - 1 and maze[i][j+1] == '.':
            q.append((i, j + 1, d + 1))
    else:
        return d-1

h,w = map(int,input().split())
maze = [list(input()) for _ in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans,dfs(maze,i,j))
print(ans)