N, M = gets.split.map(&:to_i)
Ikr = Hash.new{|h,k| h[k] = 100001 }
Tkr = Array.new(N){ [] }
M.times{|i|
	a, c = gets.to_i, gets.split.map(&:to_i)
	kg = c.inject(0){|kg, tkr|
		kg | (1<<(tkr-1))
	}
	Ikr[kg] = [Ikr[kg], a].min
	Tkr[c[0]-1] << kg
}
N.times{|i|
	Tkr[i].each{|kg1|
		cost1 = Ikr[kg1]
		(i+1).upto(N-1){|j|
			Tkr[j].each{|kg2|
				cost2 = Ikr[kg2]
				Ikr[kg1|kg2] = [Ikr[kg1|kg2], cost1+cost2].min
			}
		}
	}
}
p Ikr.fetch((1<<N)-1, -1)
