def resolve():
    from collections import deque
    h, w = map(int, input().split())
    maze = [list(input()) for _ in range(h)]
    def mazesolver(x, y):
        visited = [[0]*w for _ in range(h)]
        mark = deque([[x, y]])
        times = [[0]*w for _ in range(h)]
        visited[x][y] = 1
        times[x][y] = 1
        xchange = [-1,0,1,0]
        ychange = [0,1,0,-1]
        while mark:
            tx, ty = mark.pop()
            visited[tx][ty] = 1
            a = times[tx][ty]
            for i in range (3):
                nx = tx + xchange[i]
                ny = ty + ychange[i]
                if 0 <= nx < h and 0 <= ny < w and visited[nx][ny] == 0 and maze[nx][ny] != "#":
                    mark.appendleft([nx,ny])
                    if times[nx][ny] == 0:
                        times[nx][ny] = a+1
        return max(max(times[i] for i in range(h)))
    ans = 0
    for l in range(h):
        for m in range(w):
            if maze[l][m] != "#":
                ans = max(ans, (mazesolver(l,m)))
    print(ans-1)
resolve()