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, kc_cost|
	min = nil
	return Tkr[tkr].map{|kg|
		additional_cost = keycase[kg] == 0 ? Ikr[kg] : 0
		next min if min and min <= kc_cost+additional_cost
		keycase[kg] += 1
		cost = tkr+1 < N ? X[tkr+1, keycase, kc_cost+additional_cost] : kc_cost+additional_cost
		keycase[kg] -= 1
		next cost
	}.min
}
p X[0, Hash.new{|h,k| h[k]=0 }, 0]
