import queue
H,W = map(int,input().split())
Maze=[]
for h in range(H):
    Maze.append(input())
max_length = 0
for i in range(H):
    for j in range(W):
        Dist = [[-1 for _ in range(W)] for __ in range(H)]
        if Maze[i][j]=='#':
            continue
        Dist[i][j]=0
        q=queue.Queue()
        q.put([i,j])
        di = [1,0,-1,0]
        dj = [0,1,0,-1]
        while not q.empty():
            pos = q.get()
            for k in range(4):
                ni = di[k] + pos[0]
                nj = dj[k] + pos[1]
                if ni<0 or nj<0 or ni>H-1 or nj>W-1:
                    continue
                if Maze[ni][nj]=='#':
                    continue
                if not Dist[ni][nj]==-1:
                    continue
                Dist[ni][nj] = Dist[pos[0]][pos[1]] + 1
                q.put([ni,nj])
        max_length = max(max_length,max(max(Dist)))

print(max_length)






