import queue
def search(sy,sx,ey,ex):
    global H,W,Maze
    q = queue.Queue()

    Visit = [[-1]*W for _ in range(H)]
    Dir = [[0,1],[0,-1],[1,0],[-1,0]]

    Visit[sy][sx] = 0 
    q.put([sy,sx])

    while not q.empty():
        ty,tx = q.get()
        path = Visit[ty][tx]

        for dy,dx in Dir:
            ny = ty + dy
            nx = tx + dx
            if 0 <= ny and ny < H and 0 <= nx and nx < W:
                if Maze[ny][nx] == '.':
                    if ny == ey and nx == ex:
                        return path+1

                    if Visit[ny][nx] == -1:
                        Visit[ny][nx] = path+1
                        q.put([ny,nx])
    return -1

H,W = map(int,input().split())
Maze = []
for h in range(H):
    Maze.append(input())

ans = 0
for sy in range(H):
    for sx in range(W):
        if Maze[sy][sx] == '#':
            continue
        for ey in range(H):
            for ex in range(W):
                if Maze[ey][ex] == '#':
                    continue
                if sx == ex and sy == ey:
                    continue
                p = search(sy,sx,ey,ex)          
                if p != -1:
                    ans = max(ans,p)
print(ans)
