N, M = gets.chomp.split.map(&:to_i)
keys = Array.new(M) do
  price, _num = gets.chomp.split.map(&:to_i)
  holes = gets.chomp.split.map(&:to_i).reduce(0) {|x, i| x | 2 ** i.pred}
  [price, holes]
end

infinity = 2 ** 31
m = Array.new(2 ** N, infinity).tap {|x| x[0] = 0}

keys.each do |cost, holes|
  m.size.times do |fill|
    m[fill | holes] = [m[fill] + cost,  m[fill | holes]].min
  end
end

puts m[-1] >= infinity ? -1 : m[-1]
