import math
import sys
sys.setrecursionlimit(10**9)
H,W = map(int,input().split())

S = []
for h in range(H):
    s = input()
    t = []
    for ss in s:
        if ss==".":
            t.append(True)
        else:
            t.append(False)
    S.append(t)

# print(S)

V = H*W

d = [[float("inf") for i in range(V)] for j in range(V)]

for h in range(H):
    for w in range(W):
        i = h*W+w
        if S[h][w]:
            if 0<=h<=H-2 and S[h+1][w]:
                j = (h+1)*W+w
                d[i][j], d[j][i] = 1,1
            if 1<=h<=H-1 and S[h-1][w]:
                j = (h-1)*W+w
                d[i][j], d[j][i] = 1,1
            if 0<=w<=W-2 and S[h][w+1]:
                j = h*W+(w+1)
                d[i][j], d[j][i] = 1,1
            if 1<=w<=W-1 and S[h][w-1]:
                j = h*W+(w-1)
                d[i][j], d[j][i] = 1,1

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

    return d #d[i][j]に頂点i, j間の最短距離を格納

# 例一個作ってみる．
dd = warshall_floyd(d, V)

# print(dd)
mx = 0
for ddd in dd:
    for n in ddd:
        if math.isfinite(n):
            mx = max(mx, n)

print(mx)

# 6 4
# #...
# #.#.
# #...
# #.#.
# #.#.
# #.#.


