We have N locked treasure boxes, numbered 1 to N.
A shop sells M keys. The i-th key is sold for a_i yen (the currency of Japan), and it can unlock b_i of the boxes: Box c_{i1}, c_{i2}, ..., c_{i{b_i}}. Each key purchased can be used any number of times.
Find the minimum cost required to unlock all the treasure boxes. If it is impossible to unlock all of them, print -1.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N \leq 12
 - 1 \leq M \leq 10^3
 - 1 \leq a_i \leq 10^5
 - 1 \leq b_i \leq N
 - 1 \leq c_{i1} < c_{i2} < ... < c_{i{b_i}} \leq N

-----Input-----
Input is given from Standard Input in the following format:
N M
a_1 b_1
c_{11} c_{12} ... c_{1{b_1}}
:
a_M b_M
c_{M1} c_{M2} ... c_{M{b_M}}

-----Output-----
Print the minimum cost required to unlock all the treasure boxes.
If it is impossible to unlock all of them, print -1.

-----Sample Input-----
2 3
10 1
1
15 1
2
30 2
1 2

-----Sample Output-----
25

We can unlock all the boxes by purchasing the first and second keys, at the cost of 25 yen, which is the minimum cost required.

Difficulty: interview

Starter code:

Solutions:
n, m = map(int, input().split())
valists = [10**9 for _ in range(1<<n)]
valists[0] = 0
for i in range(m):
	values, b = map(int, input().split())
	c = list(map(int, input().split()))
	cnt = 0
	for j in range(b):
		cnt += 2**(c[j]-1)
	for j in range(len(valists)):
		x = j|cnt
		valists[x] = min(valists[x], valists[j]+values)
		#print(j, cnt, x, valists)

#print(valists)
ans = valists[2**n-1]
if ans != 10**9:
	print(ans)
else:
	print(-1)

n,m=map(int,input().split())

dp=[10**9]*(1<<n)
dp[0]=0
for _ in range(m):
    a,b=map(int,input().split())
    key=0
    for i in map(int,input().split()):
        key+=1<<(i-1)
    for i in range(1<<n):
        dp[i|key]=min(dp[i|key],dp[i]+a)
if dp[-1]>10**8:
    print(-1)
else:
    print(dp[-1])

def main():
    n,m = tuple([int(t)for t in input().split()])

    keys = []

    dp = [10**9]*(1<<n)
    dp[0] = 0
    for _ in range(m):
        a,_ = tuple([int(t)for t in input().split()])
        c = tuple([int(t)for t in input().split()])
        key = 0
        for c_i in c:
            key |= 1<<(c_i-1)
        keys.append((a,key))
    

    for a,key in keys:
        for i in range(1<<n):
            dp[i|key] = min(dp[i|key],dp[i]+a)

    if dp[-1]==10**9:
        print(-1)
    else:
        print(dp[-1])
def __starting_point():
    main()
__starting_point()

import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N,M = list(map(int,readline().split()))
k = 2**N
dp = [INF for i in range(k)]
dp[0] = 0

for i in range(M):
    a,b = list(map(int,readline().split()))
    c = list(map(int,readline().split()))
    d = sum(1<<(ci-1) for ci in c)
    dpnew = dp[:]
    for j in range(k):
        dpnew[j|d] = min(dp[j]+a,dpnew[j|d])
    dp = dpnew

print((dp[2**N-1] if dp[2**N-1] != INF else -1))




n,m=map(int,input().split())
dp=[10**20]*(1<<n)
dp[0]=0
for i in range(m):
    a,b=map(int,input().split())
    c=list(map(int,input().split()))
    bit=0
    for j in c:bit|=1<<(j-1)
    for j in range(1<<n):
        dp[j|bit]=min(dp[j|bit],dp[j]+a)
if dp[-1]==10**20:print(-1)
else:print(dp[-1])

n,m=list(map(int,input().split()))
inf=10**9
cost=[inf for i in range(m)]
for i in range(m):
  a,b=list(map(int,input().split()))
  c=[int(x)-1 for x in input().split()]
  s=0
  for j in c:
    s|=1<<j
  cost[i]=[s,a]
#print(cost)

dp=[inf]*(1<<n)
dp[0]=0
for s in range(1<<n):
  for bit,c in cost:
    dp[s|bit]=min(dp[s|bit], dp[s]+c)
#print(dp)
print((-1 if dp[-1]==inf else dp[-1]))



def main():
  n, m = map(int, input().split())
  
  dp = [0]*(2**n)
  len_dp = len(dp)

  key_list = dict()
  sub = 1
  for i in range(n):
    key_list[i+1] = sub
    sub *= 2

  for _ in range(m):
    a, b = map(int, input().split())
    c = [int(x) for x in input().split()]
    key = 0
    for value in c:
      key += key_list[value]
    for i in range(len_dp-1, -1, -1):
      if i == 0 or dp[i]:
        if dp[i|key]:
          dp[i|key] = min([dp[i]+a, dp[i|key]])
        else:
          dp[i|key] = dp[i]+a

  print(dp[len_dp-1] if dp[len_dp-1] else -1)

def __starting_point():
  main()
__starting_point()

import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = list(map(int, input().split()))
    keys = []
    for _ in range(m):
        a, b = list(map(int, input().split()))
        C = list(map(int, input().split()))
        s = 0
        for c in C:
            s |= 1 << (c - 1)
        keys.append([a, s])

    dp = [f_inf] * (1 << n)
    dp[0] = 0
    for now in range(1 << n):
        for cost, key in keys:
            nxt = now | key
            dp[nxt] = min(dp[nxt], dp[now] + cost)
    print((dp[-1] if dp[-1] != f_inf else -1))


def __starting_point():
    resolve()

__starting_point()

N, M = list(map(int, input().split()))
A = []
min_state = [10**9] * (2**N)
min_state[0] = 0
for _ in range(M):
    a, b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    key = 0
    for tmp in c:
        key += 2**(tmp-1)
    A.append((a, key))
L = len(min_state)
for a, key in A:
    for i, score in enumerate(min_state):
        next_key = key | i

        if min_state[next_key] > score + a:
            min_state[next_key] = score + a
if min_state[-1] == 10**9:
    print((-1))
else:
    print((min_state[-1]))



import sys


def main():
    input = sys.stdin.readline

    n, m = list(map(int, input().split()))

    INF = 10**8
    dp = [INF] * ((1 << n) + 1)
    dp[0] = 0

    for i in range(m):
        a, b = list(map(int, input().split()))
        c = sum(1 << (ci - 1) for ci in map(int, input().split()))

        for j in range(1 << n):
            if dp[j] + a < dp[j | c]:
                dp[j | c] = dp[j] + a
            # dp[j | c] = min(dp[j] + a, dp[j | c])

    ans = -1 if dp[(1 << n) - 1] == INF else dp[(1 << n) - 1]

    print(ans)


def __starting_point():
    main()

__starting_point()

import sys
input = sys.stdin.readline

def solve():
    INF = 10**10

    N, M = list(map(int, input().split()))
    keys = []
    costs = []
    for _ in range(M):
        a, b = list(map(int, input().split()))
        costs.append(a)
        cs = list(map(int, input().split()))
        key = 0
        for c in cs:
            key |= 1<<(c-1)
        keys.append(key)

    dp = [INF] * (1<<N)
    dp[0] = 0
    for S in range(1<<N):
        for key, cost in zip(keys, costs):
            S2 = S | key
            c2 = dp[S] + cost
            if c2 < dp[S2]:
                dp[S2] = c2

    if dp[-1] == INF:
        print((-1))
    else:
        print((dp[-1]))


solve()


from functools import reduce
N, M = map(int, input().split())
L = 1 << N
table = {0: 0}
for _ in range(M):
    cost, _ = map(int, input().split())
    match = reduce(lambda a, b: a | b, (1 << shamt for shamt in map(lambda n: int(n) - 1, input().split())))
    for l, now in table.copy().items():
        table[l | match] = min(now + cost, table.get(l | match, 10 ** 7))
print(table[L - 1] if table.get(L - 1, False) else -1)

N,M=list(map(int,input().split()))
INF=10**18
dp=[INF]*(1<<N)
dp[0]=0
cost=[None]*M
target=[0]*M

for i in range(M):
    cost[i],b=list(map(int,input().split()))
    
    c=[int(x) for x in input().split()]
    for j in c:
        target[i]=target[i]|(1<<(j-1))
    
for s in range(1<<N):
    for i in range(M):
        ns=s|target[i]
        dp[ns]=min(dp[ns],dp[s]+cost[i])
if dp[-1]==INF:
    print((-1))
else :
    print((dp[-1]))


def main():
  n,m=map(int,input().split())
  inf=10**9
  cost=[inf for i in range(m)]
  for i in range(m):
    a,b=map(int,input().split())
    c=[int(x)-1 for x in input().split()]
    s=0
    for j in c:
      s|=1<<j
    cost[i]=[s,a]
  #print(cost)

  dp=[inf]*(1<<n)
  dp[0]=0
  for s in range(1<<n):
    for bit,c in cost:
      dp[s|bit]=min(dp[s|bit], dp[s]+c)
  #print(dp)
  print(-1 if dp[-1]==inf else dp[-1])

def __starting_point():
  main()
__starting_point()

import sys
readline = sys.stdin.readline

N,M = list(map(int,readline().split()))

INF = 10 ** 9
dp = [INF] * (2 ** N)
dp[0] = 0
for i in range(M):
  a,b = list(map(int,readline().split()))
  C = list(map(int,readline().split()))
  key = 0
  for c in C:
    key += (1 << (c - 1))
  for j in range(len(dp) - 1, -1, -1):
    if dp[j] == INF:
      continue
    dp[j | key] = min(dp[j | key], dp[j] + a)

if dp[-1] == INF:
  print((-1))
else:
  print((dp[-1]))


import sys
readline = sys.stdin.readline

N,M = list(map(int,readline().split()))

INF = 10 ** 9
dp = [INF] * (2 ** N)
dp[0] = 0
for i in range(M):
  a,b = list(map(int,readline().split()))
  C = list(map(int,readline().split()))
  key = 0
  for c in C:
    key += (1 << (c - 1))
  for j in range(len(dp) - 1, -1, -1):
    if dp[j] == INF:
      continue
    if dp[j | key] > dp[j] + a:
      dp[j | key] = dp[j] + a

if dp[-1] == INF:
  print((-1))
else:
  print((dp[-1]))


def main():
  N,M=map(int,input().split())
  A=[0]*M
  import heapq
  import collections
  from itertools import permutations
  table=collections.defaultdict(list)
  AC=[[0,0] for i in range(M)]
  C=[set() for i in range(M)]
  for i in range(M):
    a,b=map(int,input().split())
    AC[i][0]=a
    tmp=set(map(int,input().split()))
    for x in tmp:
      AC[i][1] |= 1<<(x-1)
  dp=[10**9]*(2**N)
  dp[0]=0

  for i in range(1,2**N):
    k=0
    s=set()
    for j in range(1,i):
      if i & j == j:
        dp[i]=min(dp[i],dp[j]+dp[i^j])
    for a,c in AC:
      if c&i == i:
        dp[i]=min(dp[i],a)
    #print(dp[i],bin(i))

  if dp[-1]==10**9:
    print(-1)
  else:
    print(dp[-1])
main()

def solve():
  ans = 0
  N, M = map(int, input().split())
  A,C = [0]*M,[0]*M
  for i in range(M):
    A[i],b = map(int, input().split())
    c = list(map(int, input().split()))
    for j in range(b):
      C[i] += 1<<(c[j]-1)
  dp = [float('inf')]*(1<<N)
  dp[0] = 0
  for i in range(1,(1<<N)+1):
    for key in range(M):
      if C[key] & i == 0:
        continue
      dp[i] = min(dp[i],dp[i&~C[key]]+A[key])
  ans = dp[-1]
  if ans==float('inf'):
    return -1
  return ans
print(solve())

def main():
    n, m = map(int, input().split())
    costs = [None]*m
    keys = [None]*m
    pattern = 2**n
    inf = 10**12
    dp = [inf]*pattern
    for i in range(m):
        costs[i] = int(input().split()[0])
        keys[i] = sum([1<<(int(i)-1) for i in input().split()])
    dp[0] = 0
    for i in range(pattern):
        for cost, key in zip(costs, keys):
            pi = i|key
            if dp[pi] > cost + dp[i]:
                dp[pi] = cost + dp[i]
    if dp[pattern-1] == inf:
        print(-1)
    else:
        print(dp[pattern-1])
        

def __starting_point():
    main()
__starting_point()

N,M = map(int,input().split())
from collections import defaultdict
INF = float('inf')
dic = defaultdict(lambda: INF)
for i in range(M):
    a,b = map(int,input().split())
    c = list(map(int,input().split()))
    d = 0
    for k in c:
        d |= (1<<(k-1))
    dic[d] = min(dic[d], a)

dp = [INF] * (1<<N)
dp[0] = 0
for k,v in dic.items():
    for b in range((1<<N)-1):
        if dp[b] == INF: continue
        if b == (b|k): continue
        dp[b|k] = min(dp[b|k], dp[b]+v)
print(-1 if dp[-1]==INF else dp[-1])                

n,m = list(map(int,input().split()))
x = 2**n
dp = [1000000000 for _ in range(x)]
dp[0] = 0
for i in range(m):
    ai,bi = list(map(int,input().split()))
    c = list(map(int,input().split()))
    bit = 0
    for j in range(bi):
        bit += 2**(c[j]-1)
    for k in range(x):
        dp[k | bit] = min(dp[k | bit],dp[k] + ai)
if dp[x-1] == 1000000000:
    print((-1))
else:
    print((dp[x-1]))


from sys import stdin

n,m = map(int,stdin.readline().rstrip().split())
c = []
a_list = []

def main():
    for i in range(m):
        a,b = map(int,stdin.readline().rstrip().split())
        a_list.append(a)
        c.append(sum(1 << j-1 for j in list(map(int,stdin.readline().rstrip().split()))))

    inf = 10**10
    dp = [inf]*(1 << n)
    dp[0] = 0

    for i in range(1 << n):
        for A,C in zip(a_list,c):
            dp[C|i] = min(dp[C|i],dp[i]+A)

    if dp[-1] == inf:
        print(-1)
    else:
        print(dp[-1])

def __starting_point():
    main()
__starting_point()

def min(a,b):
  return a if a<=b else b


def main():
  n,m=map(int,input().split())
  inf=10**9
  cost=[0]*m
  dp=[inf]*(1<<n)
  dp[0]=0
  for i in range(m):
    a,b=map(int,input().split())
    t=sum([1<<(int(x)-1) for x in input().split()])
    for s in range(1<<n):
      dp[t|s]=min(dp[t|s], dp[s]+a)
  print(-1 if dp[-1]==inf else dp[-1])
  
  
def __starting_point():
  main()
__starting_point()

N, M = map(int, input().split())
a = []
b = []
c = []

MY_INF = 1000000007

for _ in range(M):
    a_tmp, b_tmp = map(int, input().split())
    a.append(a_tmp)
    b.append(b_tmp)
    c.append(list(map(int, input().split())))

c_bin = []
for i in range(M):
    c_bin.append(sum([1 << (cij - 1) for cij in c[i]]))
    
memo = [None] * (1 << N)

def dp(state):
    nonlocal MY_INF
    if state == (1 << N) - 1: return 0
    if memo[state] != None: return memo[state]
    #
    rets = [MY_INF]
    for i in range(M):
        if (state | c_bin[i]) > state:
            rets.append(a[i] + dp((state | c_bin[i])))
    ret = min(rets)
    #
    memo[state] = ret
    return ret

ans = dp(0)
if ans != MY_INF:
    print(ans)
else:
    print(-1)

def main():
  n,m=map(int,input().split())
  inf=10**9
  dp=[inf]*(1<<n)
  dp[0]=0
  
  #cost=[inf for i in range(m)]
  for i in range(m):
    a,b=map(int,input().split())
    c=[int(x)-1 for x in input().split()]
    t=0
    for j in c:
      t|=1<<j
    #cost[i]=[s,a]
    for s in range(1<<n):
      dp[t|s]=min(dp[t|s], dp[s]+a)
    
  #print(cost)
  """
  dp=[inf]*(1<<n)
  dp[0]=0
  for s in range(1<<n):
    for bit,c in cost:
      dp[s|bit]=min(dp[s|bit], dp[s]+c)
  #print(dp)
  """
  #print(dp)
  print(-1 if dp[-1]==inf else dp[-1])

def __starting_point():
  main()
__starting_point()

import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,m=map(int,input().split())
    dp=[10**10]*(1<<n)
    dp[0]=0
    for i in range(m):
        a,b=map(int,input().split())
        C=list(map(int,input().split()))
        d=0
        for c in C:
            d|=1<<(c-1)
        for j in range(1<<n):
            dp[j|d]=min(dp[j|d],dp[j]+a)
    if dp[-1]==10**10:
        print(-1)
    else:
        print(dp[-1])
        
def __starting_point():
    main()
__starting_point()

def main():
    inf = 10 ** 8 + 1
    N, M = list(map(int, input().split()))

    dp = [inf] * (1 << N)
    dp[0] = 0

    for _ in range(M):
        price, _ = list(map(int, input().split()))
        c = (int(x) - 1 for x in input().split())
        k = sum(1 << x for x in c)
        for bit in reversed(list(range(1 << N))):
            nbit = bit | k
            dp[nbit] = min(dp[nbit], dp[bit] + price)

    ans = dp[(1 << N) - 1]
    if ans == inf:
        print((-1))
    else:
        print(ans)


def __starting_point():
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

__starting_point()

n, m = map(int, input().split())
dp = [float("inf") for i in range(1 << n)]
dp[0] = 0
for i in range(m):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    bit = 0
    for j in range(b):
        bit |= 1 << (c[j] - 1)
    for j in range(1 << n):
        dp[j | bit] = min(dp[j | bit], dp[j] + a)
if dp[-1] == float("inf"):
    print("-1")
else:
    print(dp[-1])

# -*- coding: utf-8 -*-
"""
E - Get Everything
https://atcoder.jp/contests/abc142/tasks/abc142_e

"""
import sys


def solve(N, M):
    dp = [float('inf')] * 2**N
    dp[0] = 0
    for y in range(1, M+1):
        a, b = list(map(int, input().split()))
        c = [int(i) for i in input().split()]
        t = 0
        for cc in c:
            t |= (1 << (cc-1))
        for x in range(2**N):
            if dp[x|t] > dp[x] + a:
                dp[x|t] = dp[x] + a
    return -1 if dp[-1] == float('inf') else dp[-1]


def main(args):
    N, M = list(map(int, input().split()))
    ans = solve(N, M)
    print(ans)


def __starting_point():
    main(sys.argv[1:])

__starting_point()

import sys
input = sys.stdin.readline

n, m = list(map(int, input().split()))

INF = 10**8
dp = [INF] * ((1 << n) + 1)
dp[0] = 0

for i in range(m):
    a, b = list(map(int, input().split()))
    c = sum(1 << (ci - 1) for ci in map(int, input().split()))

    for j in range(1 << n):
        # if dp[j] + a < dp[j | c]:
        #     dp[j | c] = dp[j] + a
        dp[j | c] = min(dp[j] + a, dp[j | c])

ans = -1 if dp[(1 << n) - 1] == INF else dp[(1 << n) - 1]

print(ans)


def main():
    n, m = list(map(int, input().split()))
    DP = [10**9] * 2**n
    DP[0] = 0
    updated_patterns = {0}
    for _ in range(m):
        cost, types = list(map(int, input().split()))
        to_open = list(map(int, input().split()))

        openable = 0
        for open in to_open:
            openable += 1 << (open-1)
        new_updated = set()
        for opened in updated_patterns:
            pattern = opened | openable
            new_cost = DP[opened] + cost
            if DP[pattern] > new_cost:
                DP[pattern] = new_cost
                new_updated.add(pattern)

        updated_patterns |= new_updated

    full_open = 2**n - 1
    ans = DP[full_open]
    if ans == 10 ** 9:
        ans = -1

    print(ans)


def __starting_point():
    main()

__starting_point()

import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
INF = 10 ** 10
dp = [INF] * (2 ** N)
dp[0] = 0

for i in range(M):
  a,b = map(int,readline().split())
  c = list(map(int,readline().split()))
  key = 0
  for j in range(len(c)):
    key += (1 << (c[j] - 1))
  for j in range(len(dp)):
    if dp[j] == INF:
      continue
    if j | key == j:
      continue
    if dp[j | key] > dp[j] + a:
      dp[j | key] = dp[j] + a

if dp[-1] == INF:
  print(-1)
else:
  print(dp[-1])

import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: list(map(int, sys.stdin.readline().split()))
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n, m = ns()
    d = []
    for _ in range(m):
        ai, bi = ns()
        ci = na()
        d.append([ai, bi, ci])

    # bit DP
    # dp[i] = iの各bitが1である番目の宝箱を開けられる状態となれる最小コスト
    dp = [INF for _ in range(2 ** n)]
    dp[0] = 0

    for ai, bi, ci in d:
        getkey = 0
        for cii in ci:
            cii -= 1
            getkey += 1 << cii

        for i in range(2 ** n):
            dp[i | getkey] = min(dp[i | getkey], dp[i] + ai)

    tmp = dp[2 ** n - 1]
    print((tmp if tmp != INF else -1))


def __starting_point():
    main()

__starting_point()

# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, M, ABCi):
    inf = 10 ** 5 * 12 * 2
    for i in range(M):
        C = ABCi[i][2]
        ABCi[i][2] = sum([2 ** (c - 1) for c in C])
    # dp[i番目までのカギだけ購入したときに][bin(j)の宝箱が開けられる最小金額]
    dp = [[inf] * (2 ** N) for _ in range(M + 1)]
    dp[0][0] = 0
    for i in range(1, M + 1):
        for j in range(2 ** N):
            a, b, c = ABCi[i - 1]
            dp[i][j] = min(dp[i - 1][(c & j) ^ j] + a, dp[i - 1][j])
    ans = min([x[2 ** N - 1] for x in dp])
    if ans == inf:
        ans = -1
    print(ans)


def __starting_point():
    N, M = list(map(int, input().split()))
    ABCi = [
        [int(i) for i in input().split()] + [[int(i) for i in input().split()]]
        for _ in range(M)]
    solve(N, M, ABCi)

    # # test
    # from random import randint, sample
    # from func import random_str
    # N, M = 12, 10 ** 3
    # tmp = [i for i in range(1, N + 1)]
    # ABCi = [[randint(1, 10 ** 5), randint(1, N)] for _ in range(M)]
    # print(ABCi)
    # for i in range(M):
    #     ABCi[i].append(sample(tmp, ABCi[i][1]))
    # solve(N, M, ABCi)

__starting_point()

N,M = map(int,input().split())
key = []
for i in range(M):
  a,b = map(int,input().split())
  C = list(map(int,input().split()))
  s = 0
  for i in range(b):
    C[i] -=1 #oindex
    s = s|1<<C[i] #それぞれの宝箱の番号で左シフトしてorをとることでどの宝箱を開けられるかを保存。
  key.append((s,a)) #開けられる宝箱とコストを保存
#print(key)
INF = float("inf")  
dp = [INF for _ in range(1<<N)]
dp[0] = 0
#配るDP O(2^N*M)
for s in range(1<<N): #小さい順からやるとうまく遷移ができる。
  for i in range(M): #すべてのカギについて遷移を試す。
    t = s|key[i][0] #現在の宝箱の状態sに対して、新しい鍵を加えたときに開けられる宝箱の状態。 
    dp[t] = min(dp[t],dp[s] + key[i][1])
#print(dp)
if dp[-1] == INF:
  ans = -1
else:
  ans = dp[-1]
print(ans)

def chmin(l, i, v):
  if l[i] > v:
    l[i] = v
    return True
  return False

def main():
    N, M = map(int, input().split())
    keys = []
    for i in range(M):
        a, b = map(int, input().split())
        C = map(int, input().split())
        # mask: nビット目が1なら、n番目のカギを開けられる
        mask = 0
        for c in C:
            mask |= 1 << (c-1)
        keys.append((a, mask))
    
    # N 個のカギを選ぶ、選ばないのパターンを考えると、その組み合わせは2^N 通り
    # コスト無限大で初期化
    patterns = 1 << N
    INF = float("inf")
    # dp[i]: iのnビット目が1なら、n番目のカギを開けられて、その開けられるカギの組み合わせでの最安値を示している
    # 例: dp[3]: 1番目と2番目のカギをあけたいときの最安値
    dp = [ INF ] * patterns
    dp[0] = 0

    # 計算量: O(2^N * M) => 最大でも 4096 * 10^3 ~= 10^6
    for a, mask in keys:
        for i in range(patterns):
            chmin(dp, i|mask, dp[i] + a)

    ans = dp[patterns-1]
    print(-1 if ans == INF else ans)

def __starting_point():
    main()
__starting_point()

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()

key_lis = []
key_cost = []

for _ in range(M):
	a, b = MAP()
	c = LIST()
	key = 0
	for x in c:
		key += 2**(x-1)
	key_lis.append(key)
	key_cost.append(a)


dp = [INF]*(1<<N)
dp[0] = 0

for S in range(1<<N):
	for i, key in enumerate(key_lis):
		dp[S|key] = min(dp[S|key], dp[S]+key_cost[i])

if dp[-1] == INF:
	print(-1)
else:
	print(dp[-1])

n,m=list(map(int,input().split()))
g=(1<<n)

dp=[float("inf")]*g
dp[0]=0
for i in range(m):
    a,b=list(map(int,input().split()))
    c_l=list(map(int,input().split()))
    f=0
    for c_i in c_l:
        f+=1<<(c_i-1)
    for j in range(g-1, -1, -1):
        dp[j|f]=min(dp[j]+a, dp[j|f])

print((-1 if dp[-1]==float("inf") else dp[-1]))


n,m = map(int, input().split())

abcsl = []
for _ in range(m):
    a,b = map(int, input().split())
    cl = list(map(int, input().split()))
    abcsl.append((a,b,cl))

# dp = [ [10**9]*(2**n) for _ in range(m) ]
dp = [10**9]*(2**n)
dp[0] = 0
for a,b,cl in abcsl:
    b_bit = 0
    for c in cl:
        b_bit += 2**(c-1)
    for i in range(2**n):
        dp[i|b_bit] = min(dp[i]+a, dp[i|b_bit])

if dp[2**n-1] == 10**9:
    print(-1)
else:
    print(dp[2**n-1])

N,M = map(int,input().split())
INF = 10 ** 10
dp = [INF] * (2 ** N)
dp[0] = 0

for i in range(M):
  a,b = map(int,input().split())
  c = list(map(int,input().split()))
  key = 0
  for j in range(len(c)):
    key += (1 << (c[j] - 1))
  for j in range(len(dp) - 1, -1, -1):
    if dp[j] == INF:
      continue
    dp[j | key] = min(dp[j | key], dp[j] + a)

print((dp[-1], -1)[dp[-1] == INF])

n, m = map(int, input().split())
keys = []
for i in range(m):
    a, b = map(int, input().split())
    s = 0
    for c in map(int, input().split()):
        c -= 1
        s |= 1 << c
    keys.append((s, a))

INF = 1001001001
dp = [INF] * (1<<n)
dp[0] = 0
for s in range(1<<n):
    for k, v in keys:
        t = s | k
        cost = dp[s] + v
        dp[t] = min(dp[t], cost)

ans = dp[-1]
if ans == INF: ans = -1
print(ans)

import sys

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    L = pow(2, N)
    Dist = [10 ** 20] * L
    
    Dist[0] = 0
    for _ in range(M):
        a, b = map(int, input().split())
        bit = 0
        C = [int(c) for c in input().split()]
        for c in C: bit += pow(2, c-1)
        for k in range(L):
            if Dist[k] < 10 ** 20: Dist[k | bit] = min(Dist[k | bit], Dist[k] + a)
    if Dist[L - 1] == 10 ** 20: print(-1)
    else: print(Dist[L - 1])



    return 0

def __starting_point():
    solve()
__starting_point()

n, m = map(int, input().split())
a = [None]*m
c = [0]*m
for i in range(m):
    a[i], b = map(int, input().split())
    ls = list(map(int,input().split()))
    for j in ls:
        c[i] |= 1<<(j-1)
n2 = 1<<n
dp = [1e9]*(n2)
dp[0] = 0
for i in range(m):
    for S in range(n2):
        if dp[S|c[i]] > dp[S]+a[i]:
            dp[S|c[i]] = dp[S]+a[i]
if dp[(n2)-1] < 1e9:
    print(dp[(n2)-1])
else:
    print(-1)

import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, M = list(map(int, input().split()))

    dp = [INF for i in range(1 << N)]
    dp[0] = 0

    key = []
    for _ in range(M):
        a, b = list(map(int, input().split()))
        C = tuple([int(x) - 1 for x in input().split()])
        status = 0
        for c in C:
            status += 2 ** c
        key.append((a, status))

    for a, status in key:
        if dp[status] > a:
            dp[status] = a

    for i in range(2 ** N - 1):
        for a, status in key:
            new_status = status | i
            if dp[new_status] > dp[i] + a:
                dp[new_status] = dp[i] + a

    if dp[-1] == INF:
        print((-1))
    else:
        print((dp[-1]))


def __starting_point():
    main()

__starting_point()

n, m = list(map(int, input().split()))
keys = []

for _ in range(m):
    cost, types = list(map(int, input().split()))
    to_open = list(map(int, input().split()))
    keys.append([cost, to_open])

DP = [10**9] * (2**n)
DP[0] = 0

for cost, (to_open) in keys:
    openable = 0
    for open in to_open:
        openable |= 1 << (open-1)

    for opened in range(2 ** n):
        pattern = opened | openable
        DP[pattern] = min(DP[pattern], DP[opened] + cost)

full_open = 2**n - 1
ans = DP[full_open]

if ans == 10 ** 9:
    ans = -1

print(ans)


MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

def main():
    N,M = list(map(int,input().split()))
    key = []
    for _ in range(M):
        a,b = list(map(int,input().split()))
        c = list(map(int,input().split()))
        can_open = 0
        for i in c:
            can_open ^= 1<<(i - 1)
        key.append((a,can_open))
    
    dp = [[INF] * (1<<N) for _ in range(M + 1)]
    for i in range(M):
        dp[i][0] = 0
    
    for i in range(M):
        price,can_open = key[i]
        for s in range(1,1<<N):
            dp[i + 1][s] = min(dp[i][s],dp[i][(s&can_open)^s] + price)
    print((dp[-1][-1] if dp[-1][-1] != INF else -1))

def __starting_point():
    main()

__starting_point()

import sys
input = sys.stdin.readline

n, m = list(map(int, input().split()))
dp = [float('inf')] * (2 ** n)
dp[0] = 0
for i in range(m):
    a, b = list(map(int, input().split()))
    c = sum(1 << (i - 1) for i in map(int, input().split()))
    for j in range(2 ** n):
        if dp[c | j] > dp[j] + a:
            dp[c | j] = dp[j] + a

if dp[-1] == float('inf'):
    ans = -1
else:
    ans = dp[-1]
print(ans)


n,m=map(int,input().split())
key=[]
for _ in range(m):
  a,b=map(int,input().split())
  c=list(map(int,input().split()))
  bi=0
  for i in c:
    bi+=1<<(i-1)
  key.append([a,bi])
#print(key)

INF=2**24
dp=[INF]*(1<<n)
dp[0]=0
for k in key:
  for b in range(1<<n):
    dp[b|k[1]]=min(dp[b|k[1]],dp[b]+k[0])
    #print(b,k[1],b|k[1],dp)
    
print(-1 if dp[-1]==INF else dp[-1])

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
	N, M = MAP()
	dp = [INF]*(1<<N)
	dp[0] = 0

	for _ in range(M):
		a, b = MAP()
		c = LIST()
		tmp = 0
		for x in c:
			tmp = tmp|1<<(x-1)
		for S in range(1<<N):
			dp[S|tmp] = min(dp[S|tmp], dp[S]+a)

	print((dp[-1] if dp[-1] != INF else -1))

def __starting_point():
	main()

__starting_point()

N,M=map(int,input().split())
dp=[10**10]*(1<<N)
dp[0]=0
for i in range(M):
  a,b=map(int,input().split()) 
  c=list(map(int, input().split()))
  d=0
  for j in c:
    d|=1<<j-1
  for k in range(1<<N):
    dp[k|d]=min(dp[k|d],dp[k]+a)
if dp[-1]==10**10:
  print(-1)
else:
  print(dp[-1])

INF = 10**9
n, m = list(map(int, input().split()))
keys = []
for _ in range(m):
    a, _ = list(map(int, input().split()))
    c = 0
    for i in input().split():
        c += 2**(int(i)-1)
    keys.append((a, c))

dp = [INF]*(2**n)
dp[0] = 0
for a, c in keys:
    tmp = [INF]*(2**n)
    for j, d in enumerate(dp):
        if d == INF:
            continue
        if d < tmp[j]:
            tmp[j] = d
        if d+a < tmp[j|c]:
            tmp[j|c] = d+a
    dp = tmp

print((dp[-1] if dp[-1]<INF else -1))


import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = list(map(int, input().split()))
    A, C = [], []
    for _ in range(m):
        a, b = list(map(int, input().split()))
        A.append(a)
        key = 0
        for c in map(int, input().split()):
            key |= 1 << (c - 1)
        C.append(key)

    dp = [f_inf] * (1 << n)
    dp[0] = 0
    for S in range(1 << n):
        for i in range(m):
            key, cost = C[i], A[i]
            dp[S | key] = min(dp[S | key], dp[S] + cost)
    print((dp[-1] if dp[-1] != f_inf else -1))


def __starting_point():
    resolve()

__starting_point()

n,m = map(int,input().split())
INF = 10**10

B = [INF]*(1<<n)
B[0] = 0

for _ in range(m):
  a,b = map(int,input().split())
  C = list(map(int,input().split()))
  opens = 0
  for c in C:
    opens |= (1<<(c-1))
  
  for i in range(2**n):
    if B[i|opens] > B[i]+a:
      B[i|opens] = B[i]+a

if B[(1<<n)-1]==INF:
  print(-1)
else:
  print(B[(1<<n)-1])

import sys

input = sys.stdin.readline


def main():
    N, M = list(map(int, input().split()))
    A = [0] * M
    C = [0] * M
    for i in range(M):
        A[i], _ = list(map(int, input().split()))
        C[i] = sum(2 ** (int(c) - 1) for c in input().split())

    INF = 10 ** 18
    dp = [INF] * (2 ** N)
    dp[0] = 0
    for a, c in zip(A, C):
        for s in range(2 ** N):
            dp[s | c] = min(dp[s | c], dp[s] + a)

    ans = dp[-1] if dp[-1] != INF else -1
    print(ans)


def __starting_point():
    main()

__starting_point()



def main():
    n,m=list(map(int,input().split()))

    L=2**n

    cost=[0]+[10**8 for i in range(L-1)]

    for _ in range(m):
        a,b = list(map(int,input().split()))

        c = sum([2**(int(x)-1) for x in input().split()])
        for i in range(L):
            q = c|i
            cost[q] = min(cost[q], cost[i]+a)
    print((cost[L-1] if cost[L-1]<10**8 else -1))

def __starting_point():
    main()

__starting_point()

n, m = list(map(int, input().split()))
can_open = []
cost = []
for _ in range(m):
    a, b = list(map(int, input().split()))
    cost.append(a)
    can_open.append(sum(1 << (c-1) for c in map(int, input().split())))

n_bit = 1 << n
INF = 10**18
dp = [INF]*n_bit
dp[0] = 0

for x, y in zip(can_open, cost):
    for j in range(n_bit):
        m = j | x
        z = dp[j]+y
        if dp[m] > z:
            dp[m] = z

print((dp[-1] if dp[-1] != INF else -1))


import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N,M = list(map(int,readline().split()))
k = 2**N
dp = [INF]*k 
dp[0] = 0

for i in range(M):
    a,b = list(map(int,readline().split()))
    c = list(map(int,readline().split()))
    d = sum(1<<(ci-1) for ci in c)
    dpnew = dp[:]
    for j in range(k):
        dpnew[j|d] = min(dp[j]+a,dpnew[j|d])
    dp = dpnew

print((dp[2**N-1] if dp[2**N-1] != INF else -1))




import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
keys = [None] * M
for i in range(M):
  cost,b = map(int,readline().split())
  bit = 0
  target = list(map(int,readline().split()))
  for t in target:
    bit += (1 << (t - 1))
  keys[i] = (cost, bit)
    
# 全ての鍵の組み合わせでDP
INF = 10 ** 8 + 1
dp = [INF for i in range(2 ** N)]
dp[0] = 0
for key in keys:
  cost, bit = key
  for j in range(len(dp) - 1, -1, -1):
    if dp[j] == -1:
      continue
    if dp[j | bit] > dp[j] + cost:
      dp[j | bit] = dp[j] + cost

if dp[-1] == INF:
  print(-1)
else:
  print(dp[-1])

from itertools import product
import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
can_open = []
cost = []
for _ in range(m):
    a, b = list(map(int, input().split()))
    cost.append(a)
    can_open.append(sum(1 << (c-1) for c in map(int, input().split())))

n_bit = 1 << n
INF = 10**18
dp = [INF]*n_bit
dp[0] = 0

for j, (x, y) in product(list(range(n_bit)), list(zip(can_open, cost))):
    m = j | x
    z = dp[j]+y
    if dp[m] > z:
        dp[m] = z

print((dp[-1] if dp[-1] != INF else -1))


def main():
    n,m=map(int,input().split())
    a=[0]*m
    c=[0]*m
    INF=10**9
    dp=[INF]*2**n
    for i in range(m):
        a[i]=int(input().split()[0])
        c[i]=sum([1<<(int(i)-1) for i in input().split()])
    dp[0]=0
    for i in range(2**n):
        for cos,pat in zip(a,c):
            npat=i|pat
            if dp[npat]>cos+dp[i]:
                dp[npat]=cos+dp[i]
    if dp[2**n-1]==INF:
        print(-1)
    else:
        print(dp[2**n-1])

def __starting_point():
    main()
__starting_point()

n,m = map(int, input().split())
dp = [0]*(2**n + 1)
for i in range(m):
  a,b = map(int, input().split())
  c = list(map(int, input().split()))
  temp=0
  for i in c:
    temp += 2 ** (i-1)
  for i in range(2**n):
    if i != 0 and dp[i] == 0:
      continue
    t = i | temp
    if dp[t] == 0:
      dp[t] = dp[i] + a
    else:
      dp[t] = min(dp[i] + a, dp[t])

ans = dp[2**n - 1]
if ans == 0:
  print(-1)
else:
  print(ans)

import sys

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    Dist = [10 ** 20] * pow(2, N)
    Dist[0] = 0
    for _ in range(M):
        a, b = map(int, input().split())
        C = [int(c) for c in input().split()]
        binaryC = 0
        for c in C: binaryC += pow(2, c-1)
        for j, d in enumerate(Dist):
            if d < 10 ** 20: Dist[j | binaryC] = min(Dist[j | binaryC], Dist[j] + a)
    print(Dist[-1] if Dist[-1] < 10 ** 20 else -1)

    return 0

def __starting_point():
    solve()
__starting_point()

def main():
    import numpy as np

    n, m = list(map(int, input().split()))
    dp = np.full(2**n, 10**9, dtype=np.int64)
    dp[0] = 0
    opened = np.arange(2**n)

    for _ in range(m):
        cost, types = list(map(int, input().split()))
        to_open = np.array(list(map(int, input().split())), dtype=np.int64)

        openable = np.left_shift(1, to_open-1).sum()
        new_indexes = opened | openable
        new_costs = dp + cost
        sort_index = np.argsort(new_costs)
        new_costs.sort()
        update_pattern, idx = np.unique(new_indexes[sort_index], return_index=True)
        update_cost = new_costs[idx]
        dp[update_pattern] = np.minimum(dp[update_pattern], update_cost)

    full_open = 2**n - 1
    ans = dp[full_open]
    if ans == 10 ** 9:
        ans = -1

    print(ans)


def __starting_point():
    main()

__starting_point()

import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = list(map(int, input().split()))
    keys = []
    for _ in range(m):
        bit = ["0"] * n
        a, b = list(map(int, input().split()))
        C = list(map(int, input().split()))
        for c in C:
            bit[c - 1] = "1"
        bit = int("".join(bit), 2)
        keys.append([bit, a])

    dp = [f_inf] * (1 << n)
    dp[0] = 0
    for i in range(1 << n):
        for k, cost in keys:
            idx = i | k
            dp[idx] = min(dp[idx], dp[i] + cost)

    print((dp[-1] if dp[-1] != f_inf else -1))


def __starting_point():
    resolve()

__starting_point()

import sys
def input(): return sys.stdin.readline().rstrip()


def main():
    n, m = map(int, input().split())
    price = [0]*m
    typesnum = [0]*m
    keybit=[0]*m
    for i in range(m):
        price[i], typesnum[i] = map(int, input().split())
        keybit[i] = sum(map(lambda x: 2**(int(x)-1), input().split()))
    dp = [10**9]*(1 << n)
    dp[0]=0
    for bit in range(1 << n):
        for i in range(m):
            dp[bit | keybit[i]] = min(dp[bit | keybit[i]], dp[bit]+price[i])
    if dp[-1] == 10**9:
        dp[-1] = -1
    print(dp[-1])


def __starting_point():
    main()
__starting_point()

import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = list(map(int, input().split()))
    ABC = []
    for _ in range(m):
        a, b = list(map(int, input().split()))
        C = list(map(int, input().split()))
        s = ["0"] * n
        for c in C:
            s[c - 1] = "1"

        c = "".join(s[::-1])
        ABC.append([a, b, int(c, 2)])

    dp = [f_inf for _ in range(1 << n)]
    dp[0] = 0
    for a, b, c in ABC:
        for i in range(1 << n):
            idx = i | c
            dp[idx] = min(dp[idx], dp[i] + a)

    if dp[-1] == f_inf:
        print((-1))
    else:
        print((dp[-1]))


def __starting_point():
    resolve()

__starting_point()

#!/usr/bin python3
# -*- coding: utf-8 -*-

INF = 10**6

n, m = list(map(int, input().split()))
dp = [INF] * (2**n)
dp[0] = 0
for i in range(m):
    a, b = list(map(int, input().split()))
    bit = ['0'] * n
    for x in set(map(int, input().split())):
        bit[x-1] = '1'
    bit = int(''.join(bit[::-1]), 2)
    for j in range(2**n-1, -1, -1):
        dp[j|bit] = min(dp[j|bit], a + dp[j])
if dp[-1] == INF:
    print((-1))
else:
    print((dp[-1]))


N,M = map(int,input().split())
COST = []
B = []
C = []
C_bit = []
INF = 10**18
dp = [INF]*(1<<N)
dp[0] = 0

for _ in range(M):
  a,b = map(int,input().split())
  C.append(list(map(int,input().split())))
  COST.append(a)
  B.append(b)

for i in range(M):
  bit = ['0']*N
  for j in range(B[i]):
    bit[C[i][j]-1] = '1'
  bit_int = int(''.join(bit),2)
  C_bit.append(bit_int)

for cost,c in zip(COST,C_bit):
  for i in range(1<<N):
    j = i|c
    d = dp[i]+cost
    if dp[j] > d:
      dp[j] = d

if dp[-1] == INF:
  print(-1)
else:
  print(dp[-1])

n,m=map(int,input().split())
key=[]
for _ in range(m):
  a,b=map(int,input().split())
  c=list(map(int,input().split()))
  bi=0
  for i in c:
    bi+=2**(i-1)
  key.append([a,bi])
dp=[10**10]*(2**n)
dp[0]=0
for k in key:
  for b in range(2**n):
    dp[b|k[1]]=min(dp[b|k[1]],dp[b]+k[0])
if dp[-1]==10**10:
  print(-1)
else:
  print(dp[-1])

def main():
    n, m = list(map(int, input().split()))
    all_patterns = 2**n
    DP = [10**9] * all_patterns
    DP[0] = 0
    for _ in range(m):
        cost, types = list(map(int, input().split()))
        to_open = list(map(int, input().split()))

        openable = 0
        for open in to_open:
            openable += 1 << (open-1)

        for opened in range(all_patterns):
            pattern = opened | openable
            new_cost = DP[opened] + cost
            if DP[pattern] > new_cost:
                DP[pattern] = new_cost

    full_open = 2**n - 1
    ans = DP[full_open]
    if ans == 10 ** 9:
        ans = -1
        
    print(ans)


def __starting_point():
    main()

__starting_point()

#!usr/bin/env python3
import sys

MOD = 10 ** 9 + 7
INF = 10 ** 18
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)


def main():
    N, M = map(int, input().split())
    keys = []
    for _ in range(M):
        a, b = map(int, input().split())
        bits = sum([1 << (i - 1) for i in map(int, input().split())])
        keys.append([a, bits])

    dp = [INF] * (2 ** N + 10)
    dp[0] = 0

    for i in range(M):
        for j in range(2 ** N):
            dp[j | keys[i][1]] = min(dp[j | keys[i][1]], dp[j] + keys[i][0])
    print(dp[2 ** N - 1] if dp[2 ** N - 1] != INF else -1)


def __starting_point():
    main()
__starting_point()

import sys
input = sys.stdin.readline

def solve():
    INF = 10**10

    N, M = list(map(int, input().split()))
    keys = []
    costs = []
    for _ in range(M):
        a, b = list(map(int, input().split()))
        costs.append(a)
        cs = list(map(int, input().split()))
        key = 0
        for c in cs:
            key |= 1<<(c-1)
        keys.append(key)

    dp = [INF] * (1<<N)
    dp[0] = 0
    for key, cost in zip(keys, costs):
        for S in reversed(list(range(1<<N))):
            S2 = S | key
            c2 = dp[S] + cost
            if c2 < dp[S2]:
                dp[S2] = c2

    if dp[-1] == INF:
        print((-1))
    else:
        print((dp[-1]))


solve()


import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
INF = 10 ** 10
dp = [INF] * (2 ** N)
dp[0] = 0

for i in range(M):
  a,b = map(int,readline().split())
  c = list(map(int,readline().split()))
  key = 0
  for j in range(len(c)):
    key += (1 << (c[j] - 1))
  for j in range(len(dp)):
    if dp[j] == INF:
      continue
    if j | key == j:
      continue
    dp[j | key] = min(dp[j | key], dp[j] + a)

if dp[-1] == INF:
  print(-1)
else:
  print(dp[-1])

import sys

input = sys.stdin.readline
INF = float("inf")


def main():
    N, M = list(map(int, input().split()))
    keys = [None] * M
    for i in range(M):
        a, b = list(map(int, input().split()))
        s = 0
        for c in map(int, input().split()):
            c -= 1
            s |= 1 << c
        keys[i] = (s, a)

    dp = [INF] * (2 ** N)
    dp[0] = 0
    for s in range(2 ** N):
        for key, a in keys:
            t = s | key
            dp[t] = min(dp[t], dp[s] + a)

    ans = dp[-1] if dp[-1] != INF else -1
    print(ans)


def __starting_point():
    main()

__starting_point()

def main():
  n,m=map(int,input().split())
  inf=10**9
  dp=[inf]*(1<<n)
  dp[0]=0
  
  #cost=[inf for i in range(m)]
  for i in range(m):
    a,b=map(int,input().split())
    c=[1<<(int(x)-1) for x in input().split()]
    t=sum(c)
    #cost[i]=[s,a]
    for s in range(1<<n):
      dp[t|s]=min(dp[t|s], dp[s]+a)
    
  #print(cost)
  """
  dp=[inf]*(1<<n)
  dp[0]=0
  for s in range(1<<n):
    for bit,c in cost:
      dp[s|bit]=min(dp[s|bit], dp[s]+c)
  #print(dp)
  """
  #print(dp)
  print(-1 if dp[-1]==inf else dp[-1])

def __starting_point():
  main()
__starting_point()

import sys
from collections import defaultdict


def input():
    return sys.stdin.readline().strip()


MOD = 10 ** 9 + 7
sys.setrecursionlimit(20000000)
INF = float("inf")


def main():
    N, M = list(map(int, input().split()))
    key = []
    for _ in range(M):
        a, b = list(map(int, input().split()))
        C = list([int(x) - 1 for x in input().split()])
        state = 0
        for c in C:
            state += 2 ** c
        key.append((a, state))
    dp = [INF for _ in range(2 ** N)]
    dp[0] = 0
    for i in range(2 ** N - 1):
        for k in range(M):
            state = key[k][1]
            tmp = dp[i] + key[k][0]
            if dp[i | state] > tmp:
                dp[i | state] = tmp
    if dp[-1] == INF:
        print((-1))
    else:
        print((dp[-1]))


def __starting_point():
    main()

__starting_point()

def main():
  N, M = list(map(int, input().split()))
  inf =  10**15
  p = 1<<N
  dp = [inf]*p
  dp[0] = 0
  for i in range(M):
    a, b = list(map(int, input().split()))
    c = sum(1<<(i-1) for i in map(int, input().split()))
    for j in range(p):
      dp[c|j] = min(dp[j]+a, dp[c|j])
  if dp[-1] == inf:
    print((-1))
  else: 
    print((int(dp[-1])))
  
def __starting_point():
  main()

__starting_point()

n ,m= list(map(int,input().split()))
kagi = [[]for _ in range(m)] 
#a円　b種類開けられる
for i in range(m):
    a,b =  list(map(int,input().split()))
    X =  list(map(int,input().split()))
    bit = 0
    for x in X:
        bit |= 2**(x-1)
    kagi[i] = [a,bit]

ok = 2**n-1#全部空いたらこれ
kagi.sort(key=lambda x: x[1])
zenkai = 2**n
dp = [float('inf')]*int(zenkai+1)
dp[0] = 0
for i in range(2**n):
    if dp[i] == float('inf'):
        continue
    for j in range(m):
        s = i|kagi[j][1]
        # print(s)
        dp[s] = min(dp[s],dp[i] + kagi[j][0])
# print(dp)
if dp[zenkai-1] == float('inf'):
    print(-1)
else:
    print(dp[zenkai-1])

import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = list(map(int, input().split()))
    ABC = []
    for _ in range(m):
        a, b = list(map(int, input().split()))
        C = list(map(int, input().split()))
        bit = ["0"] * n
        for c in C:
            bit[c - 1] = "1"

        bit = "".join(bit)
        ABC.append([a, b, int(bit, 2)])

    dp = [f_inf for _ in range(1 << n)]
    dp[0] = 0
    for i in range(1 << n):
        for a, b, c in ABC:
            idx = i | c
            dp[idx] = min(dp[idx], dp[i] + a)

    if dp[-1] != f_inf:
        print((dp[-1]))
    else:
        print((-1))


def __starting_point():
    resolve()

__starting_point()

import sys
import itertools

N,M = map(int, input().split())
AB = []
C = []
for _ in range(M):
    AB.append(tuple(map(int, input().split())))
    C.append(sum(1<<(int(x)-1) for x in map(int, input().split())))

INF = 10**18
dp = [INF]*(1<<N)
dp[0] = 0

for n,((a,b),c) in itertools.product(range(1<<N), zip(AB,C)):
    m = n|c
    x = dp[n] + a
    if dp[m] > x:
        dp[m] = x

ans = dp[-1]
if ans == INF:
    ans = -1
print(ans)

def main():
  n,m=map(int,input().split())
  inf=10**9
  dp=[inf]*(1<<n)
  dp[0]=0
  
  #cost=[inf for i in range(m)]
  for i in range(m):
    a,b=map(int,input().split())
    c=[1<<(int(x)-1) for x in input().split()]
    t=sum(c)
    #cost[i]=[s,a]
    for s in range(1<<n):
      if dp[t|s]>dp[s]+a:
        dp[t|s]=dp[s]+a
      #dp[t|s]=min(dp[t|s], dp[s]+a)
    
  #print(cost)
  """
  dp=[inf]*(1<<n)
  dp[0]=0
  for s in range(1<<n):
    for bit,c in cost:
      dp[s|bit]=min(dp[s|bit], dp[s]+c)
  #print(dp)
  """
  #print(dp)
  print(-1 if dp[-1]==inf else dp[-1])

def __starting_point():
  main()
__starting_point()

import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
keys = [None] * M
for i in range(M):
  cost,b = map(int,readline().split())
  bit = 0
  target = list(map(int,readline().split()))
  for t in target:
    bit += (1 << (t - 1))
  keys[i] = (cost, bit)
    
# 全ての鍵の組み合わせでDP
INF = 10 ** 8 + 1
dp = [INF for i in range(2 ** N)]
dp[0] = 0
for key in keys:
  cost, bit = key
  for j in range(len(dp) - 1, -1, -1):
    if dp[j] == INF:
      continue
    if dp[j | bit] > dp[j] + cost:
      dp[j | bit] = dp[j] + cost

if dp[-1] == INF:
  print(-1)
else:
  print(dp[-1])

import sys
input = sys.stdin.readline

def main():
  n, m = map(int, input().split())
  U = 2**n
  dp = [ [float("inf")]*(2**n) for _ in range(m) ]
  dp[0][0] = 0
  for i in range(1, m):
    a, b = map(int, input().split())
    k = map(int, input().split())
    c = 0
    for l in k:
      c |= 1<<(l-1)
    for j in range(U):
      dp[i][j] = min(dp[i-1][j&(~c)]+a, dp[i-1][j])

  if dp[m-1][2**n-1] == float("inf"):
    print(-1)
  else:
    print(dp[m-1][2**n-1])
    
def __starting_point():
  main()
__starting_point()

N,M = map(int,input().split())
dp = [float('inf')]*2 ** N
dp[0] = 0
for _ in range(M):
  a, b = map(int, input().split())
  c = sum([2**(int(i)-1) for i in input().split()])
  for s in range(2**N):
    t = s|c
    if dp[t] > dp[s] + a:
      dp[t] = dp[s] +a
ans = dp[-1]
if dp[-1] == float('inf'):
  print(-1)
else:
  print(ans)

import sys

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    L = pow(2, N)
    Inf = pow(10, 20)
    Dist = [Inf] * L
    
    Dist[0] = 0
    for _ in range(M):
        a, b = map(int, input().split())
        bit = 0
        C = [int(c) for c in input().split()]
        for c in C: bit += pow(2, c-1)
        for k, d in enumerate(Dist):
            if d < Inf: Dist[k | bit] = min(Dist[k | bit], d + a)
            
    print(Dist[L - 1] if Dist[L-1] < Inf else -1)

    return 0

def __starting_point():
    solve()
__starting_point()

#!/usr/bin python3
# -*- coding: utf-8 -*-

INF = 10**6

n, m = list(map(int, input().split()))
dp = [INF] * (2**n)
dp[0] = 0
for i in range(m):
    a, b = list(map(int, input().split()))
    bit = ['0'] * n
    for x in set(map(int, input().split())):
        bit[x-1] = '1'
    bit = int(''.join(bit), 2)
    for j in range(2**n-1, -1, -1):
        dp[j|bit] = min(dp[j|bit], a + dp[j])
if dp[-1] == INF:
    print((-1))
else:
    print((dp[-1]))


n, m = list(map(int, input().split()))

DP = [10**9] * (2**n)
DP[0] = 0
for _ in range(m):
    cost, types = list(map(int, input().split()))
    to_open = list(map(int, input().split()))

    openable = 0
    for open in to_open:
        openable += 1 << (open-1)

    for opened in range(2 ** n):
        pattern = opened | openable
        DP[pattern] = min(DP[pattern], DP[opened] + cost)

full_open = 2**n - 1
ans = DP[full_open]

if ans == 10 ** 9:
    ans = -1

print(ans)


N, M = list(map(int, input().split()))
K = []

for _ in range(M):
    a, _ = list(map(int, input().split()))
    k = 0
    for i in [int(a) - 1 for a in input().split()]:
        k |= (1 << i)
    K.append((a, k))

dp = [10**18] * (1 << N)
dp[0] = 0
for state in range(1 << N):
    for a, k in K:
        if dp[state | k] > dp[state] + a:
            dp[state | k] = dp[state] + a
ans = dp[(1 << N) - 1]
print((ans if ans < 10**18 else -1))


import sys
input = sys.stdin.readline

n, m = list(map(int, input().split()))

INF = 10**8
dp = [INF] * ((1 << n) + 1)
dp[0] = 0

for i in range(m):
    a, b = list(map(int, input().split()))
    c = sum(1 << (ci - 1) for ci in map(int, input().split()))

    for j in range(1 << n):
        if dp[j] + a < dp[j | c]:
            dp[j | c] = dp[j] + a
        # dp[j | c] = min(dp[j] + a, dp[j | c])

ans = -1 if dp[(1 << n) - 1] == INF else dp[(1 << n) - 1]

print(ans)


def main():
  N, M = map(int, input().split())
  inf =  10**9
  p = 1<<N
  dp = [inf]*p 
  dp[0] = 0
  for i in range(M):
    a, b = map(int, input().split())
    C = list(map(int, input().split()))
    c_bit = sum([1<<(c-1) for c in C])
    for j in range(p):
      #print(min(dp[i][j|c_bit], dp[i][j] + a))
      dp[j|c_bit] = min(dp[j|c_bit], dp[j] + a)
  if dp[p-1] == inf:
    print(-1)
  else: 
    print(int(dp[p-1]))
  
def __starting_point():
  main() 
__starting_point()

def main():
  n,m=list(map(int,input().split()))
  inf=10**9
  dp=[inf]*(1<<n)
  dp[0]=0
  for i in range(m):
    a,b=list(map(int,input().split()))
    t=sum([1<<(int(x)-1) for x in input().split()])
    for s in range(1<<n):
      dp[t|s]=dp[t|s] if dp[t|s]<=dp[s]+a else dp[s]+a
  print((-1 if dp[-1]==inf else dp[-1]))
  
  
def __starting_point():
  main()

__starting_point()

n,m = list(map(int,input().split()))
dp = [2**63]*4096
dp[0] = 0
for i in range(m):
  a,b = list(map(int,input().split()))
  mask = 0
  c = list(map(int,input().split()))
  for i in c:
    mask |= ( 1 << i-1 )
  nxtdp = dp[:]
  for j in range(1 << n):
    if dp[j] < 2 ** 63:
      nxtdp[j | mask] = min(nxtdp[j | mask], dp[j] + a)
  dp = nxtdp
print((dp[(1<<n)-1] if dp[(1<<n)-1] < 2**63 else -1))


N, M = map(int,input().split())
dp = [float("inf")]*(2**N)
dp[0] = 0
for i in range(1, M+1):
    a,b = map(int,input().split())
    c = list(map(int,input().split()))
    d = 0
    for j  in range(1, N+1):
        if j in c:
            d += 2**(j-1)
    for j in range(2**N):
        dp[j | d] = min(dp[j | d], dp[j] + a)
print(dp[-1] if dp[-1] != float("inf") else -1)