N, M = gets.split.map(&:to_i)

Q, Ikr, FullBit = [], Hash.new{|h,k| h[k] = 100001 }, (1<<N)-1
master_key = 0
M.times{|i|
	a, c = gets.to_i, gets.split.map(&:to_i)
	tkrbit = c.inject(0){|bit, tkr|
		bit | (1<<(tkr-1))
	}
	master_key |= tkrbit
	Q << ((a<<N)|tkrbit)
}
if master_key != FullBit
	p -1
	exit
end

Q.sort!
while lowest = Q.shift
	low_cost, low_tkrbit = lowest>>N, lowest&FullBit
	next if Ikr[low_tkrbit] < low_cost
	break if low_tkrbit == FullBit

	q, r = [], []
	while kg = Q.shift
		cost, tkrbit = kg>>N, kg&FullBit
		next if Ikr[tkrbit] < cost
		q << kg

		cost, tkrbit = cost+low_cost, tkrbit|low_tkrbit
		next if Ikr[tkrbit] <= cost
		Ikr[tkrbit] = cost
		r << ((cost<<N)|tkrbit)
	end

	until q.empty?
		unless r.empty?
			Q << (q[0] < r[0] ? q : r).shift
		else
			Q.concat(q)
			q.clear
		end
	end
	Q.concat r
end
p Ikr[FullBit]
