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

keys = []
prices = []

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

  prices << a
  keys << gets.split.map(&:to_i)
end

ans = Float::INFINITY

1.upto(2 ** N - 1) do |i|
  list = []
  v = 0

  M.times do |j|
    next if i[j] == 0

    v += prices[j]
    list |= keys[j]
  end

  if list.sort == [*1..N] && v < ans
    ans = v
  end
end

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