from queue import Queue
from copy import deepcopy

h, w = map(int, input().split())
s = [input() for _ in range(h)]

WHITE = 0
GRAY = 1
BLACK = 2

dhw = [[-1, 0], [1, 0], [0, -1], [0, 1]]

color_orginal = [[WHITE] * w for _ in range(h)]
for hi in range(h):
    for wi in range(w):
        if s[hi][wi] == "#":
            color_orginal[hi][wi] = BLACK


def dfs(sh, sw):
    q = Queue()
    q.put([sh, sw])

    color = deepcopy(color_orginal)
    d = [[-1] * w for _ in range(h)]

    d[sh][sw] = 0
    dd = 0

    while not q.empty():
        uh, uw = q.get()
        color[uh][uw] = BLACK
        for dh, dw in dhw:
            nxth = uh + dh
            nxtw = uw + dw
            if 0 <= nxth <= h - 1 and 0 <= nxtw <= w - 1:
                if color[nxth][nxtw] == WHITE:
                    q.put([nxth, nxtw])
                    color[nxth][nxtw] = GRAY
                    d[nxth][nxtw] = d[uh][uw] + 1
                    dd = max(d[nxth][nxtw], dd)

    return dd


ans = 0
for hi in range(h):
    for wi in range(w):
        ans = max(ans, dfs(hi, wi))

print(ans)
