parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	h,w = readline() |> split |> parseMap
	s = String["" for i in 1:h]
	for i in 1:h
		s[i]=readline() |> chomp
	end
	k = 0
	for i in 1:h
		for j in 1:w
			if s[i][j]=='.'
				g = -ones(Int,h,w)
				vst = zeros(Int,h,w)
				g[i,j] = 0
				vst[i,j] = 1
				stack = Tuple{Int,Int}[(i,j)]
				while !isempty(stack)
					now = shift!(stack)
					x = now[1]
					y = now[2]
					if x>1
						if s[x-1][y]=='.'&&vst[x-1,y]==0
							vst[x-1,y]=1
							g[x-1,y]=g[x,y]+1
							push!(stack,(x-1,y))
						end
					end
					if x<h
						if s[x+1][y]=='.'&&vst[x+1,y]==0
							vst[x+1,y]=1
							g[x+1,y]=g[x,y]+1
							push!(stack,(x+1,y))
						end
					end
					if y>1
						if s[x][y-1]=='.'&&vst[x,y-1]==0
							vst[x,y-1]=1
							g[x,y-1]=g[x,y]+1
							push!(stack,(x,y-1))
						end
					end
					if y>w
						if s[x][y+1]=='.'&&vst[x,y+1]==0
							vst[x,y+1]=1
							g[x,y+1]=g[x,y]+1
							push!(stack,(x,y+1))
						end
					end
				end
				k = max(k,maximum(g))
			end
		end
	end
	println(k)
end

main()