INFTY = 10**13
def floyd():
    for k in range(n):
        for i in range(n):
            if d[i][k] == INFTY:
                continue
            for j in range(n):
                if d[k][j] == INFTY:
                    continue
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])

H, W = map(int, input().split())
S = [list(input()) for h in range(H)]
n = H*W
d = [[0 if i == j else INFTY for j in range(n)]for i in range(n)]

for h in range(H):
    for w in range(W):
        for dh, dw in [(0, -1), (0, 1), (-1, 0), (1, 0)]:
            if 0 <= h + dh < H and 0 <= w + dw < W and S[h+dh][w+dw] == '.':
                d[h*W+w][(h+dh)*W+(w+dw)] = 1

floyd()

ans = max([x for row in d for x in row if x != INFTY])
print(ans)