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

def bfs(sx, sy):
    q = collections.deque([(sx, sy)])
    checked = [[0 for _ in range(w)] for _ in range(h)]
    checked[i][j] = 1
    res = 0
    while q:
        qx, qy = q.popleft()
        for dx, dy in [(0,1),(1,0),(-1,0),(0,-1)]:
            x = qx+dx
            y = qy+dy
            if 0<=x<h and 0<=y<w and s[x][y] == "." and checked[x][y]==0:
                q.append((x,y))
                checked[x][y] = checked[qx][qy]+1
                res = max(checked[x][y],res)
    return res


ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            ans = max(ans, bfs(i, j)-1)

print(ans)