import math

H,W = map(int,input().split())

S = []

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

for i in range(H):
    tmp = list(input())
    S.append([t for t in tmp])

d = [[10000 for _ in range(H*W)] for _ in range(H*W) ]
for i in range((H)*W):
    if i == H*W-1:
        pass 
    elif i % W == W-1:
        if S[i//W][i%W] == ".":
            if S[i//W+1][i%W] == ".":
                d[i][i+W] = 1
                d[i+W][i] = 1
    elif i > (H-1)*W-1:
        if S[i//W][i%W] == ".":
            if S[i//W][i%W+1] == ".":
                d[i][i+1] = 1
                d[i+1][i] = 1

    else:
        if S[i//W][i%W] == ".":
            if S[i//W+1][i%W] == ".":
                d[i][i+W] = 1
                d[i+W][i] = 1
            if S[i//W][i%W+1] == ".":
                d[i][i+1] = 1
                d[i+1][i] = 1
n = H*W
x = warshall_floyd(d)                

ans = 0
for x_ in x:
    for xx in x_:
        if xx < 10000 and xx > ans:
            ans = xx
print(ans)


