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

B, Ikr, FullBit = {}, [100001]*(1<<N), (1<<N)-1
master_key = 0
M.times{
	a, c = gets.to_i, gets.split.map(&:to_i)
	tkrbit = c.inject(0){|bit, tkr|
		bit | (1<<(tkr-1))
	}
	next if Ikr[tkrbit] < a
	master_key |= tkrbit
	Ikr[tkrbit] = a
	B[(a<<N)|tkrbit] = true
}
if master_key != FullBit
	p -1
	exit
end

Q, q, r = B.keys.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
	next unless B.key?(lowest)

	while kg = Q.shift
		cost, tkrbit = kg>>N, kg&FullBit
		next if Ikr[tkrbit] < cost
		cost, tkrbit = low_cost+cost, low_tkrbit|tkrbit
		next if tkrbit == low_tkrbit
		q << kg
		next if Ikr[tkrbit] <= cost
		Ikr[tkrbit] = cost
		r << ((cost<<N)|tkrbit)
	end

	until q.empty?
		unless r.empty?
			l, pv = q[0] < r[0] ? [q, r[0]+FullBit] : [r, q[0]+FullBit]
			Q.concat l.shift(l.bsearch_index{|_| pv <= _ }||l.size)
		else
			Q.concat q
			q.clear
		end
	end
	Q.concat r
	r.clear
end
p Ikr[FullBit]
