from collections import deque
h, w = map(int, input().split())
s = [input() for i in range(h)]
def bfs(i0, j0):
    INF = 100
    search = deque([(i0, j0)])
    d = [[INF] * w for i in range(h)]
    d[i0][j0] = 0
    while search:
        i, j = search.popleft()
        for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            ni, nj = i + di, j + dj
            if 0 <= ni < h and 0 <= nj < w and s[ni][nj] == '.' and d[ni][nj] == INF:
                search.append((ni, nj))
                d[ni][nj] = d[i][j] + 1
    return d[i][j]

max_d = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            max_dij = bfs(i, j)
            max_d = max(max_d, max_dij)
print(max_d)