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