# coding=utf-8
get = lambda: int(raw_input().strip())
gets = lambda: map(int, raw_input().strip().split())
getss = lambda x: [gets() for _ in xrange(x)]
getl = lambda x: [gets() for _ in xrange(x)]

m, n = gets()
A0 = [list(raw_input().strip()) for _ in xrange(n)]

for i in xrange(m):
    for j in xrange(n):
        if A0[i][j] == '.':
            A0[i][j] = 0
        else:
            A0[i][j] = -1


def test(i, j):
    # print '\ntest ', i, j
    A = [row[:] for row in A0]
    bfs = [[i, j]]
    A[i][j] = 1
    dep = 0
    while bfs:
        dep += 1
        bfs2 = []
        for i, j in bfs:
            for di, dj in [[0, -1], [0, 1], [-1, 0], [1, 0]]:
                i2, j2 = i + di, j + dj
                if 0 <= i2 < m and 0 <= j2 < n and A[i2][j2] == 0:
                    A[i2][j2] = dep + 1
                    bfs2.append([i2, j2])
        bfs = bfs2
    # print A
    return dep


res = 0
for i in xrange(m):
    for j in xrange(n):
        if A0[i][j] < 0: continue
        res = max(res, test(i, j) - 1)
print res
