N, M = gets.split.map(&:to_i)

prices = []
list = Hash.new { |h, k| h[k] = [] }

M.times do
  a, b = gets.split.map(&:to_i)
  keys = gets.split.map(&:to_i)

  v = 0

  keys.each do |k|
    v |= (1 << k - 1)
  end

  list[keys.first - 1] << [a, v]
end

dp = Hash.new(Float::INFINITY)
dp[0] = 0

N.times do |i|
  dp.keys.each do |current_list|
    list[i].each do |price, ks|
      n = current_list | ks
      k = dp[current_list] + price

      if k < dp[n]
        dp[n] = k
      end
    end
  end
end

ans = dp[2 ** N - 1]

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