N,M=map(int,input().split())
grid=[[c for c in input()] for _ in range(N)]
mat=[[0]*(M*N) for _ in range(N*M)]

DX=[0,0,1,-1]
DY=[-1,1,0,0]
for row in range(N):
  for col in range(M):
    if grid[row][col]=="#":
      continue
  	for dx,dy in DX,DY:
      if 0<=row+dx<N and 0<=col+dy<M:
        if grid[row+dx][col+dx]=="#":
          continue
        mat[(row+dx)*N+col+dx][dx*N+dy]=1
        mat[dx*N+dy][(row+dx)*N+col+dx]=1
for k in range(N*M):
        for i in range(N*M):
            for j in range(N*M):
                mat[i][j] = min(mat[i][j],mat[i][k] + mat[k][j])
print(max(mat))

       	
    