def dfs(i, V, E):
    S = [i]
    while(len(S) > 0):
        vi = S.pop()
        for j in E[vi]:
            if V[j] == 0:
                V[j] += V[vi] + 1
                S.append(j)
    return V


h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
p = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            p += 1
            s[i][j] = p
        else:
            s[i][j] = 0

E = [[] for _ in range(p + 1)]
for i in range(h):
    for j in range(w):
        p = s[i][j]
        if p > 0:
            if j < w - 1:
                p1 = s[i][j + 1]
                if p1 > 0:
                    E[p].append(p1)
                    E[p1].append(p)
            if i < h - 1:
                p2 = s[i + 1][j]
                if p2 > 0:
                    E[p].append(p2)
                    E[p2].append(p)

ans = 0
for i in range(1, len(E)):
    V = [0 for _ in range(len(E))]
    V_res = dfs(i, V, E)
    ans = max(ans, *V_res)
print(ans)
