from itertools import product


def solve(string):
    h, w, *os = string.split()
    h, w = int(h), int(w)
    s, os = [_s + "#" for _s in os] + ["#" * (w + 1)], "".join(os)
    n = [[] for _ in range(h * w)]
    for i, j in product(range(h), range(w)):
        if s[i][j] == "#":
            continue
        for x, y in [(1, 0), (0, 1)]:
            p, q = i + x, j + y
            if s[p][q] == ".":
                n[i * w + j].append(p * w + q)
                n[p * w + q].append(i * w + j)
    print(n)
    ans = 0
    for i, j in product(range(h), range(w)):
        c = i * w + j
        if not n[c]:
            continue
        t = [h * w + 1] * (h * w)
        t[c] = 0
        q = list()
        for d in n[c]:
            q.append((d, c))
        while q:
            d, c = q.pop()
            if t[c] + 1 >= t[d]:
                continue
            t[d] = t[c] + 1
            for _d in n[d]:
                q.append((_d, d))
        for i in range(h * w):
            ans = max(ans, t[i] * (os[i] == "."))
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))
