import sys
import collections
input=sys.stdin.readline


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


def f(sx, sy):
    q = collections.deque()
    q.append((sx, sy))
    dist = [[float("inf") for w in range(W)] for h in range(H)]
    dist[sx][sy] = 0
    dx = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    while q:
        h, w = q.popleft()
        d = dist[h][w]
        for x, y in dx:
            h2 = h + y
            w2 = w + x
            if h2 >= 0 and h2 < H and w2 >= 0 and w2 < W:
                if S[h2][w2] == "." and dist[h2][w2] == float("inf"):
                    dist[h2][w2] = d+1
                    q.append((h2, w2))
    ma = 0
    for d in dist:
        for i in d:
            if i != float("inf"):
                ma = max(ma, i)
    return ma


def main():
    ans = 0
    for y in range(H):
        for x in range(W):
            ans = max(ans, (f(y, x)))
    print(ans)


if __name__ == '__main__':
    main()
