N,M=gets.split.map &:to_i
dp=[1<<28]*(1<<N)
dp[0]=0
M.times{
	a=gets.to_i
	c=gets.split.map(&:to_i).inject{|s,x|s|1<<(x-1)}
	(1<<N).times{|i|dp[i|c]=[dp[i|c],dp[i]+a].min}
}
p dp[(1<<N)-1]==1<<28?-1:dp[(1<<N)-1]