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)
end
dp = Array.new(2 ** n, INF)
dp[0] = 0
m.times do |i|
  (0...2 ** n).each do |num|
    from = num
    keys[i].each do |box|
      if from[box - 1] == 1
        from -= 2 ** (box - 1)
      end
    end
    dp[num] = [dp[num], dp[from] + cost_num[i][0]].min
  end
end
puts dp.last == INF ? - 1 : dp.last
