from copy import deepcopy
from collections import deque
from itertools import product

H, W = map(int, input().split())
S = [list(input()) for i in range(H)]

S = [[1000000 if s == '.' else '#' for s in row] for row in S]
ans = 0
for i, j in product(range(H), range(W)):
    if S[i][j] == '#':
        continue
    d = deepcopy(S)
    d[i][j] = 0
    v = [[False] * W for i in range(H)]
    q = deque([(i, j)])
    while len(q) > 0:
        x, y = q.popleft()
        v[x][y] = True
        if 0 <= x - 1 and S[x - 1][y] != '#':
            d[x - 1][y] = min(d[x][y] + 1, d[x - 1][y])
            if not v[x - 1][y]:
                q.append((x - 1, y))
        if x + 1 < H and S[x + 1][y] != '#':
            d[x + 1][y] = min(d[x][y] + 1, d[x + 1][y])
            if not v[x + 1][y]:
                q.append((x + 1, y))
        if 0 <= y - 1 and S[x][y - 1] != '#':
            d[x][y - 1] = min(d[x][y] + 1, d[x][y - 1])
            if not v[x][y - 1]:
                q.append((x, y - 1))
        if y + 1 < W and S[x][y + 1] != '#':
            d[x][y + 1] = min(d[x][y] + 1, d[x][y + 1])
            if not v[x][y + 1]:
                q.append((x, y + 1))
    for x, y in product(range(H), range(W)):
        if v[x][y]:
            ans = max(d[x][y], ans)
print(ans)
