from functools import reduce

def ind(i, j):
    return  i * w + j

def sij(i, j):
    return ss[ind(i, j)]

def pdist(d):
    for i in range(len(d)):
        print(d[i])

def froyd(n, d):
    for k in range(n):
        for s in range(n):
            for t in range(n):
                d[s][t] = min(d[s][t], d[s][k] + d[k][t])

h, w = [int(x) for x in input().split()]
n = h * w
ss = ""
for i in range(h):
    ss += input()

INF = float("inf")
d = [[] for _ in range(n)]
for i in range(n):
    d[i] = [INF] * n
    d[i][i] = 0

# pdist(d)

# d[s][t]にsからtへのコストを入れる
for i in range(h):
    for j in range(w):
        if sij(i, j) != ".": continue
        if i > 0 and sij(i - 1, j) == ".":
            d[ind(i - 1, j)][ind(i, j)] = 1
        if i < h - 1 and sij(i + 1, j) == ".":
            d[ind(i + 1, j)][ind(i, j)] = 1
        if j > 0 and sij(i, j - 1) == ".":
            d[ind(i, j - 1)][ind(i, j)] = 1
        if j < w - 1 and sij(i, j + 1) == ".":
            d[ind(i, j + 1)][ind(i, j)] = 1

# pdist(d)

froyd(n, d)

"""
for i in range(h):
    for j in range(w):
        print(max([x for x in d[ind(i, j)] if x < INF]), end = " ")
    print()
"""

print(max([x for x in reduce(lambda a, b: a + b, d) if x < INF]))