from itertools import product

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

l=list(product((0,1),repeat=N))

L=len(l)

for i in range(2**N):

    l[i]=[l[i],1300000]

r=(2048,1024,512,256,128,64,32,16,8,4,2,1)

l[0][1]=0

for i in range(M):

    a,b=list(map(int,input().split()))

    c=tuple(map(int,input().split()))

    t=[0]*N

    for j in c:

        t[-j]=1

    for j in range(L):

        s=0

        for k in range(N):

            if l[j][0][-k-1] or t[-k-1]:

                s+=r[-k-1]

        l[s][1]=min(l[j][1]+a,l[s][1])

if l[-1][1]==1300000:

    print((-1))

else:

    print((l[-1][1]))
N,M=list(map(int,input().split()))

L=2**N

l=[float("inf")]*L

l[0]=0

r=(1,2,4,8,16,32,64,128,256,512,1024,2048)

for i in range(M):

    s=0

    a,b=list(map(int,input().split()))

    c=tuple(map(int,input().split()))

    for j in c:

        s+=r[j-1]

    for j in range(L):

        l[j|s]=min(l[j|s],l[j]+a)

if l[-1]==float("inf"):

    print((-1))

else:

    print((l[-1]))
from itertools import product

N, M = list(map(int, input().split()))
l = list(product((0, 1), repeat=N))
L = len(l)
for i in range(2**N):
    l[i] = [l[i], 1300000]
r = (2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1)
l[0][1] = 0
for i in range(M):
    a, b = list(map(int, input().split()))
    c = tuple(map(int, input().split()))
    t = [0] * N
    for j in c:
        t[-j] = 1
    for j in range(L):
        s = 0
        for k in range(N):
            if l[j][0][-k - 1] or t[-k - 1]:
                s += r[-k - 1]
        l[s][1] = min(l[j][1] + a, l[s][1])
if l[-1][1] == 1300000:
    print((-1))
else:
    print((l[-1][1]))

N, M = list(map(int, input().split()))
L = 2**N
l = [float("inf")] * L
l[0] = 0
r = (1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048)
for i in range(M):
    s = 0
    a, b = list(map(int, input().split()))
    c = tuple(map(int, input().split()))
    for j in c:
        s += r[j - 1]
    for j in range(L):
        l[j | s] = min(l[j | s], l[j] + a)
if l[-1] == float("inf"):
    print((-1))
else:
    print((l[-1]))

-from itertools import product - -l = list(product((0, 1), repeat=N)) -L = len(l) -for i in range(2**N): -    l[i] = [l[i], 1300000] -r = (2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1) -l[0][1] = 0 +L = 2**N +l = [float("inf")] * L +l[0] = 0 +r = (1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048) +    s = 0 -    t = [0] * N -        t[-j] = 1 +        s += r[j - 1] -        s = 0 -        for k in range(N): -            if l[j][0][-k - 1] or t[-k - 1]: -                s += r[-k - 1] -        l[s][1] = min(l[j][1] + a, l[s][1]) -if l[-1][1] == 1300000: +        l[j | s] = min(l[j | s], l[j] + a) +if l[-1] == float("inf"): -    print((l[-1][1])) +    print((l[-1]))