import sys
input = sys.stdin.readline
H, W = map(int, input().split())
S = [input()[:-1] for _ in [0]*H]


def bfs(h, w, H, W):
    from collections import deque
    visited = [[False]*W for _ in range(H)]
    dirs = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    q = deque()
    q.append((0, h, w))
    while q:
        d, h, w = q.popleft()
        visited[h][w] = True

        for dh, dw in dirs:
            if 0 <= h+dh < H and 0 <= w+dw < W and not visited[h+dh][w+dw] and S[h][w] == '.':
                q.append((d+1, h+dh, w+dw))

    return d, h, w


ans = 0
for h, _S in enumerate(S):
    for w, s in enumerate(_S):
        if s == '.':
            d, h, w = bfs(h, w, H, W)
            if d > ans:
                ans = d

print(ans)
