import queue

h, w = list(map(int, input().split()))
smat = [input() for _ in range(h)]

def bfs(x0, y0):
    visited = set()
    q = queue.Queue()
    q.put((x0, y0, -1))

    mx = 0
    while not q.empty():
        x, y, d = q.get()
        nd = d + 1
        visited.add((x, y))
        mx = max(mx, nd)

        for dx, dy in [(-1, 0), (0, -1), (+1, 0), (0, +1)]:
            nx = x + dx
            ny = y + dy
            if not (0 <= nx < h) or not (0 <= ny < w):
                # bound check
                continue
            if smat[nx][ny] == '#':
                # cell attr check
                continue
            if (nx, ny) in visited:
                # already visited
                continue
            v = (nx, ny, nd)
            q.put(v)
    
    return mx

mxall = 0
for x0 in range(h):
    for y0 in range(w):
        if smat[x0][y0] == '.':
            mx = bfs(x0, y0)
            mxall = max(mxall, mx)
print(mxall)
