import collections

h, w = map(int, input().split())
s = [[""]*(w+2)]
for _ in range(h):
    _s = list(input())
    _s.insert(0, "")
    _s.append("")
    s.append(_s)
s.append([""]*(w+2))

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

ans = 0

for _h in range(1, h+1):
    for _w in range(1, w+1):
        q = collections.deque([[_h, _w]])

        a = [[-1]*(w+2) for _ in range(h+2)]
        a[_h][_w] = 0

        while 0 < len(q):
            cx, cy = q.pop()
            for _dx, _dy in zip(dx, dy):
                x = cx + _dx
                y = cy + _dy

                if s[x][y] == "." and a[x][y] == -1:
                    a[x][y] = a[cx][cy] + 1
                    q.appendleft([x, y])

        for _a in a:
            ans = max(ans, max(_a))

print(ans)
