import sys
import copy
input = sys.stdin.readline
from collections import deque
H, W = [int(x) for x in input().split()]
S = []
for _ in range(H):
    S.append(list(input().rstrip()))
can = []
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            can.append([i, j])
ans = []
for u in can:
    S_ = copy.deepcopy(S)
    D = {}
    queue = deque([u])
    def bfs(u, S):
        S_2 = S[:]
        D[tuple(u)] = 0
        while queue:
            v = queue.popleft()
            x, y = v
            next_ = [[x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]]
            for r in next_:
                if 0 <= r[0] < H and 0 <= r[1] < W:
                    if S_2[r[0]][r[1]] == ".":
                        S_2[r[0]][r[1]] = "#"
                        D[tuple(r)] = D[tuple(v)] + 1
                        queue.append(r)
        return max(D.values())
    ans.append(bfs(u, S_))
print(max(ans))






