import heapq

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])

for y in range(1,H+1):
    for x in range(1,W+1):
        if S[y][x] == '.':
            q = []
            heapq.heappush(q, [0,y,x])
            while len(q) != 0:
                v = heapq.heappop(q)
                n = v[0]
                iy = v[1]
                ix = v[2]
                d[iy][ix] = n;
                for nv in G[iy][ix]:
                    if d[nv[0]][nv[1]] <= n+1 :
                        continue
                    heapq.heappush(q, [n+1, nv[0], nv[1] ] )
            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)
