from collections import deque
h,w=map(int,input().split())

maze=[]
INF=10**6
dx=[1,0,-1,0]
dy=[0,1,0,-1]

#マップ入力
for i in range(h):
    row=list(input())
    maze.append(row)


ans=0
for i in range(h):
    for j in range(w):
        queue=deque()
        d=[]
        used=[]
        for i in range(h):
            used.append([False for j in range(w)])
            d.append([INF for j in range(w)])
            
        if maze[i][j]==".":
            d[i][j]=0
            used[i][j]=True
            queue.append([i,j])

            while len(queue)>0:
                y,x=queue.popleft()
                for k in range(4):
                    nx=x+dx[k]
                    ny=y+dy[k]
                    if 0<=ny<h and 0<=nx<w:
                        if d[ny][nx]>d[y][x]+1 and maze[ny][nx]=="." and 0==used[ny][nx]:
                            d[ny][nx]=d[y][x]+1
                            ans=max(ans,d[ny][nx])
                            queue.append([ny,nx])
                            used[ny][nx]=True
print(ans)   