from copy import copy
from itertools import product
h, w = map(int, input().split())
maze = []
max_d = 0
for i in range(h):
    maze.append(input())
for i, j in product(range(h), range(w)):
    if maze[i][j] == '#':
        continue
    s = (i, j)
    for k, l in product(range(h), range(w)):
        if maze[k][l] == '#':
            continue
        g = (k, l)
        pathes = [[s]]
        while pathes:
            path = pathes.pop(0)
            a, b = path[-1]
            for point in [(0, 1), (1, 0), (0, -1),(-1, 0)]:
                di, dj = point
                if a + di >= 0 and a + di < h and b + dj >= 0 and b + dj < w and (a+di, b+dj) not in path and maze[a+di][b+dj]=='.':
                    copy_path = copy(path)
                    copy_path.append((a + di, b + dj))
                    pathes.append(copy_path)
                if (a + di, b + dj) == g:
                    max_d = max(max_d, len(copy_path)-1)
                    pathes = None
                    break
print(max_d)
                

