(n,m)=gets.split.map(&:to_i)
ac = (0...m).map{ (a,b)=gets.split.map(&:to_i);c=gets.split.map{|a|1<<(a.to_i-1)}.reduce(:|); [a,c] }

memo={}

ac.each{|v,i|
    a=memo.keys
    memo[i]=v
    a.each{|k|
        nk=k|i;
        memo[nk]||=10**9
        memo[nk] = [memo[k]+v, memo[nk]].min
    }
}

k12=(0...n).map{|x|1<<x}.reduce(:|) 
if memo[k12]
    print memo[k12]
else
    print -1
end