require 'set'
N, M = gets.split.map(&:to_i)
as = Array.new(N)
keys = Array.new(N) { [] }
ts = Set.new
M.times do |k|
  a, _ = gets.split.map(&:to_i)
  as[k] = a
  gets.split.map(&:to_i).each do |t|
    t -= 1
    keys[t].push(k)
    ts.add(t)
  end
end
if ts.size < N
  puts -1
  exit 0
end

def dfs(t, as, keys, used, sum)
  return sum if t == N
  min = 1 << 60
  keys[t].each do |k|
    a = as[k]
    already_used = false
    new_sum = sum
    if used.include?(k)
      already_used = true
    else
      new_sum += a
      used.add(k)
    end
    n = dfs(t + 1, as, keys, used, new_sum)
    used.delete(k) unless already_used
    min = n if n < min
  end
  min
end

ans = dfs(0, as, keys, Set.new, 0)
puts ans
