import numpy as np

h, w = map(int, input().split())
board = np.zeros((h, w), dtype=bool)

for i in range(h):
    line = input()
    for j, s in enumerate(line):
        board[i][j] = s == "."


def get_around(i, j):
    if i > 0:
        yield (i - 1, j)
    if i < h - 1:
        yield (i + 1, j)
    if j > 0:
        yield (i, j - 1)
    if j < w - 1:
        yield (i, j + 1)


from collections import deque


def length(start, end):
    q = deque()
    q.append((start, 0))
    seen = np.zeros((h, w), dtype=bool)
    seen[start] = True
    while q:
        cur, l = q.popleft()
        if cur == end:
            return l
        for ncur in get_around(*cur):
            if board[ncur] and not seen[ncur]:
                seen[ncur] = True
                q.append(((ncur), l + 1))


def yield_pos():
    for i in range(h):
        for j in range(w):
            if board[i, j]:
                yield (i, j)


res = 0
for start in yield_pos():
    for end in yield_pos():
        res = max(length(start, end), res)
print(res)

