h, w = map(int, input().split())
#s = [['#' for _ in range(w+2)]] + [list('#' + input() + '#') for _ in range(h)] + [['#' for _ in range(w+2)]]
s = [list(input()) for _ in range(h)]

n = h * w
m = [[float('inf') for _ in range(n)] for _ in range(n)]

#for x in m: print(x)
for i in range(h):
    for j in range(w-1):
        if s[i][j] == '.':
            if s[i][j+1] == '.':
                m[i * w + j][i * w + j + 1] = 1
                m[i * w + j + 1][i * w + j] = 1

for i in range(h-1):
    for j in range(w):
        if s[i][j] == '.':
            if s[i+1][j] == '.':
                m[i*w+j][(i+1)*w+j] = 1
                m[(i+1)*w+j][i*w+j] = 1

def warshall_floyd(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

m = warshall_floyd(m)
ans = 0
for i in range(n):
    for j in range(n):
        if m[i][j] != float('inf'):
            ans = max(ans, m[i][j])

print(ans)