import sys

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 7)

import itertools



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

AB = []

C = []

for _ in range(M):

    AB.append(tuple(int(x) for x in readline().split()))

    C.append(sum(1<<(int(x)-1) for  x in readline().split()))



INF = 10**18

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

dp[0] = 0



for n,((a,b),c) in itertools.product(list(range(1<<N)),list(zip(AB,C))):

    m = n|c

    x = dp[n]+a

    if dp[m] > x:

      dp[m] = x

      

answer = dp[-1]

if answer == INF:

    answer = -1

print(answer)

import sys

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 7)



import numpy as np



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

AB = []

C = []

for _ in range(M):

    AB.append(tuple(int(x) for x in readline().split()))

    C.append(sum(1<<(int(x)-1) for  x in readline().split()))



A,B = np.array(AB,np.int64).T

C = np.array(C,np.int64)



INF = 10**18

dp = np.full(1<<N,INF,np.int64)

dp[0] = 0



for n in range(1<<N):

    target = n|C

    value = A

    I = np.lexsort((value,target))

    target = target[I]

    value = value[I]

    is_first_elem = np.ones(M,np.bool)

    is_first_elem[1:] = ~(target[:-1] == target[1:])

    target = target[is_first_elem]

    value = value[is_first_elem]

    dp[target] = np.minimum(dp[target],dp[n]+value)



answer = dp[-1]

if answer == INF:

    answer = -1

print(answer)
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**7)
import itertools

N, M = list(map(int, readline().split()))
AB = []
C = []
for _ in range(M):
    AB.append(tuple(int(x) for x in readline().split()))
    C.append(sum(1 << (int(x) - 1) for x in readline().split()))
INF = 10**18
dp = [INF] * (1 << N)
dp[0] = 0
for n, ((a, b), c) in itertools.product(list(range(1 << N)), list(zip(AB, C))):
    m = n | c
    x = dp[n] + a
    if dp[m] > x:
        dp[m] = x
answer = dp[-1]
if answer == INF:
    answer = -1
print(answer)

import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**7)
import numpy as np

N, M = list(map(int, readline().split()))
AB = []
C = []
for _ in range(M):
    AB.append(tuple(int(x) for x in readline().split()))
    C.append(sum(1 << (int(x) - 1) for x in readline().split()))
A, B = np.array(AB, np.int64).T
C = np.array(C, np.int64)
INF = 10**18
dp = np.full(1 << N, INF, np.int64)
dp[0] = 0
for n in range(1 << N):
    target = n | C
    value = A
    I = np.lexsort((value, target))
    target = target[I]
    value = value[I]
    is_first_elem = np.ones(M, np.bool)
    is_first_elem[1:] = ~(target[:-1] == target[1:])
    target = target[is_first_elem]
    value = value[is_first_elem]
    dp[target] = np.minimum(dp[target], dp[n] + value)
answer = dp[-1]
if answer == INF:
    answer = -1
print(answer)

-import itertools +import numpy as np +A, B = np.array(AB, np.int64).T +C = np.array(C, np.int64) -dp = [INF] * (1 << N) +dp = np.full(1 << N, INF, np.int64) -for n, ((a, b), c) in itertools.product(list(range(1 << N)), list(zip(AB, C))): -    m = n | c -    x = dp[n] + a -    if dp[m] > x: -        dp[m] = x +for n in range(1 << N): +    target = n | C +    value = A +    I = np.lexsort((value, target)) +    target = target[I] +    value = value[I] +    is_first_elem = np.ones(M, np.bool) +    is_first_elem[1:] = ~(target[:-1] == target[1:]) +    target = target[is_first_elem] +    value = value[is_first_elem] +    dp[target] = np.minimum(dp[target], dp[n] + value)