import collections
h, w = map(int, input().split())
s = [[""]*(w+2)]
starts = []
for i in range(h):
    _s = list(input())
    _s.insert(0, "")
    _s.append("")
    s.append(_s)
    for j, __s in enumerate(_s):
        if __s == ".":
            starts.append([i+1, j])
s.append([""]*(w+2))

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

ans = 0
for _start in starts:
    dist = [[-1]*(w+2) for _ in range(h+2)]
    dist[_start[0]][_start[1]] = 0
    q = collections.deque([_start])

    # BFS
    while 0 < len(q):
        c = q.pop()
        for _dx, _dy in zip(dx, dy):
            x = c[0] + _dx
            y = c[1] + _dy
            if s[x][y] == "." and dist[x][y] == -1:
                dist[x][y] = dist[c[0]][c[1]] + 1
                q.appendleft([x, y])

    ans = max(ans, max(max(dist)))

print(ans)
