def resolve():
    H, W = list(map(int, input().split()))
    S = [list(input()) for _ in range(H)]
    import collections
    maxdist = 0
    for startx in range(H):
        for starty in range(W):
            visited = [[False for _ in range(W)] for __ in range(H)]
            q = collections.deque([(startx, starty, 0)])
            while q:
                x, y, dist = q.pop()
                visited[x][y] = True
                maxdist = max(maxdist, dist)
                for dx, dy in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
                    nx = x + dx
                    ny = y + dy
                    if 0 <= nx < H and 0 <= ny < W and S[nx][ny] != "#" and visited[nx][ny] is False:
                        q.appendleft((nx, ny, dist+1))
    print(maxdist)
    

if '__main__' == __name__:
    resolve()