H, W = map(int, input().split())
maze = []
for i in range(H):
    maze.append(list(input()))

import numpy as np    
from collections import deque

s = (2, 0)

def dfs(s, maze):
    H, W = maze.shape

    visited = np.array([[-1 for _ in range(W)] for _ in range(H)])
    visited[s[0]][s[1]] = 0

    actions = [(-1,0),(1,0),(0,-1),(0,1)]
    queue = deque([s])

    while queue:
        c = queue.popleft()
        for action in actions:
            nc = [0,0]
            nc[0] = c[0] + action[0]
            nc[1] = c[1] + action[1]
            if nc[0] in range(H) and nc[1] in range(W) and maze[tuple(nc)]=='.' and visited[tuple(nc)]==-1:
                visited[tuple(nc)] = visited[tuple(c)] + 1
                queue.append(nc)
    return np.max(visited)

ret = -1

for sx in range(H):
    for sy in range(W):
        if maze[sx][sy] == '.':
            ret = max(dfs((sx,sy), maze), ret)
print(ret)  