import numpy as np
N, M = map(int, input().split())
P=[[s for s in input()] for _ in range(N)]
Maze = np.zeros((N,M))
Ans = np.zeros((N,M))
List = np.zeros((N,M))
Plus = np.zeros((N,M))

for x in range(N):
    for y in range(M):
        if P[x][y]=='#':
            Maze[x][y]=-1
            List[x][y]=-1

for i in range(N):
    for j in range(M):
        if Maze[i][j]==0:
            List = np.zeros((N,M))
            List[i][j]=1
            for k in range(N*M):
                count =0
                Plus = np.zeros((N,M))
                for a in range(N):
                    for b in range(M):
                        if List[a][b]==k+1 and Maze[a][b]==0:
                            if a-1 >=0 and List[a-1][b]==0 and Maze[a-1][b]==0:
                                Plus[a-1][b]=k+2
                            if b-1 >=0 and List[a][b-1]==0 and Maze[a][b-1]==0:
                                Plus[a][b-1]=k+2
                            if a+1 <N and List[a+1][b]==0 and Maze[a+1][b]==0:
                                Plus[a+1][b]=k+2
                            if b+1 <M and List[a][b+1]==0 and Maze[a][b+1]==0:
                                Plus[a][b+1]=k+2
                List = List+Plus

        Ans[i][j]=np.amax(List)
print(np.amax(Ans)-1)
