H,W=map(int, input().split())
DINF = 100000
d = [ [ DINF for _ in range(W+2)] for _ in range(H+2)]
S = []
S.append('#' * (W+2))
for i in range(H):
    S.append('#'+ input() + '#')
S.append('#' * (W+2))
dmax = 0
G = [ [ [] for _ in range(W+2)] for _ in range(H+2)]
for y in range(1,H+1):
    for x in range(1,W+1):
        if (S[y-1][x] == '.'):  G[y][x].append([y-1,x])
        if (S[y][x-1] == '.'):  G[y][x].append([y,x-1])
        if (S[y+1][x] == '.'):  G[y][x].append([y+1,x])
        if (S[y][x+1] == '.'):  G[y][x].append([y,x+1])

def SUB(x,y,n):
    d[y][x] = n
    for v in G[y][x]:
        if d[v[0]][v[1]] > n+1:
            SUB(v[1],v[0],n+1)

for y in range(1,H+1):
    for x in range(1,W+1):
        if S[y][x] == '.':
            SUB(x,y,0)
            for iy in range(1,H+1):
                for ix in range(1,W+1):
                    if d[iy][ix] != DINF:
                        dmax = max(dmax, d[iy][ix])
                    d[iy][ix] = DINF
print(dmax)



