require 'set'
N, M = gets.split.map(&:to_i)
Ikr = [nil]*M
Tkr = Array.new(N){ [] }
M.times{|i|
	a, c = gets.to_i, gets.split.map(&:to_i)
	Ikr[i] = a
	c.each{|tkr|
		Tkr[tkr-1] << i
	}
}
if Tkr.any?{|kg| kg.empty? }
	p -1
	exit
end
Tkr.map!{|kg| kg.sort_by{|_| Ikr[_] } }

X = lambda{|tkr, keycase|
	return Tkr[tkr].map{|kg|
		keycase[kg] += 1
		cost = tkr+1 < N ? X[tkr+1, keycase] : keycase.inject(0){|sum,kv| sum + (0<kv[1] ? Ikr[kv[0]] : 0) }
		keycase[kg] -= 1
		next cost
	}.min
}
p X[0, Hash.new{|h,k| h[k]=0 }]
