Key = Struct.new(:price, :chests)

n, m = gets.split(' ').map(&:to_i)
$keys = m.times.map {
  price, _ = gets.split(' ').map(&:to_i)
  Key.new(price, gets.split(' ').map(&:to_i))
}

def solve(open_chests, spent_money)
  return spent_money if open_chests.empty?

  useful_keys = $keys.reject { |key| (key.chests & open_chests).empty? }
  return Float::INFINITY if useful_keys.empty?

  useful_keys.map.with_index { |key, index|
    solve(open_chests - key.chests, spent_money + key.price)
  }.min
end

spent_money = solve([*1..n], 0)

if spent_money == Float::INFINITY
  puts -1
else
  puts spent_money
end
