INF = 10 ** 10
n, m = gets.split.map(&:to_i)
cost_num = []
keys = []
m.times do
  cost_num << gets.split.map(&:to_i)
  keys << gets.split.map(&:to_i).inject(0) { |res, num| res | 2 ** (num - 1) }
end
dp = Array.new(2 ** n, INF)
dp[0] = 0
keys.each_with_index do |key, i|
  (0...2 ** n).each do |opened|
    current_opened = opened
    next_opened = (opened | key)
    dp[next_opened] = [dp[next_opened], dp[current_opened] + cost_num[i][0]].min
  end
end
puts dp.last == INF ? - 1 : dp.last
