import copy
h, w = map(int, input().split())
grid = []
for _ in range(h):
    grid.append(list(input()))
grid_c = copy.deepcopy(grid)
res = 0
kouho = []
for i in range(h):
    for j in range(w):
        if grid_c[i][j] != '.':
            continue
        kouho.append((i, j))
        queue = [(i, j, 0)]
        while queue:
            c_i, c_j, level = queue.pop(0)
            grid_c[c_i][c_j] = '#'
            changed = False
            for n_i, n_j in ((c_i - 1, c_j), (c_i + 1, c_j), (c_i, c_j - 1), (c_i, c_j + 1)):
                if 0 <= n_i < h and 0 <= n_j < w and grid_c[n_i][n_j] == '.':
                    queue.append((n_i, n_j, level + 1))
                    changed = True
            if changed == False:
                kouho.append((c_i, c_j))
res = 0
for i, j in kouho:
    if grid[i][j] != '.':
        continue
    visited = []
    queue = [(i, j, 0)]
    while queue:
        c_i, c_j, level = queue.pop(0)
        visited.append((c_i, c_j))
        for n_i, n_j in ((c_i - 1, c_j), (c_i + 1, c_j), (c_i, c_j - 1), (c_i, c_j + 1)):
            if 0 <= n_i < h and 0 <= n_j < w and grid[n_i][n_j] == '.' and (n_i, n_j) not in visited:
                queue.append((n_i, n_j, level + 1))
    res = max(res, level)
print(res)    