n, m = map(int, input().split())
a = []
b = []
c = []
checker = [0]*n
for _ in range(m):
    ai, bi = map(int, input().split())
    ci = list(map(int, input().split()))
    ci_int = 0
    for hako in ci:
        hako -= 1
        ci_int += 2**hako
        if checker[hako] == 0:
            checker[hako] = 1
    a.append(ai)
    b.append(bi)
    c.append(ci_int)
#print(a)
#print(b)
#print(c)
if sum(checker) != n:
    print(-1)
    exit()

dp = [[float("inf")]*(2**n) for _ in range(m+1)]
#dp[i][S]はi番目までのカギをいくつか使ってSになるようなコストの最小値
#Sは2進数で表現できる。例）１と３の箱が開けられる状態->0b101
dp[0][0] = 0
for i in range(m):
    for s in range(2**n):
        # i番目のカギを使用しない場合
        dp[i+1][s] = min(dp[i+1][s], dp[i][s])
        # 使用する場合
        dp[i+1][s | c[i]] = min(dp[i+1][s|c[i]], dp[i][s] + a[i])
print(dp[m][2**n-1]) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m a = [] a [] b = [] b [] c = [] c [] checker = [0]*n checker [0]*n [0] 0 n for _ in range(m):
    ai, bi = map(int, input().split())
    ci = list(map(int, input().split()))
    ci_int = 0
    for hako in ci:
        hako -= 1
        ci_int += 2**hako
        if checker[hako] == 0:
            checker[hako] = 1
    a.append(ai)
    b.append(bi)
    c.append(ci_int)
#print(a)
#print(b)
#print(c) _ range(m) range m ai, bi = map(int, input().split()) ai map(int, input().split()) map int input().split() ().split () input split bi ci = list(map(int, input().split())) ci list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ci_int = 0 ci_int 0 for hako in ci:
        hako -= 1
        ci_int += 2**hako
        if checker[hako] == 0:
            checker[hako] = 1
     hako ci hako -= 1 hako 1 ci_int += 2**hako ci_int 2**hako 2 hako if checker[hako] == 0:
            checker[hako] = 1
     checker[hako] == 0 checker[hako] checker hako 0 checker[hako] = 1 checker[hako] checker hako 1 a.append(ai) a.append a append ai b.append(bi) b.append b append bi c.append(ci_int) c.append c append ci_int if sum(checker) != n:
    print(-1)
    exit() sum(checker) != n sum(checker) sum checker n print(-1) print -1 exit() exit [float("inf")]*(2**n) for _ in range(m+1) for _ in range(m+1) _ range(m+1) range m+1 m 1 for _ in range(m+1) [float("inf")]*(2**n) [float("inf")] float("inf") float "inf" 2**n 2 n dp = [[float("inf")]*(2**n) for _ in range(m+1)] dp [[float("inf")]*(2**n) for _ in range(m+1)] dp[0][0] = 0 dp[0][0] [0] dp 0 0 0 for i in range(m):
    for s in range(2**n):
        # i番目のカギを使用しない場合
        dp[i+1][s] = min(dp[i+1][s], dp[i][s])
        # 使用する場合
        dp[i+1][s | c[i]] = min(dp[i+1][s|c[i]], dp[i][s] + a[i]) i range(m) range m for s in range(2**n):
        # i番目のカギを使用しない場合
        dp[i+1][s] = min(dp[i+1][s], dp[i][s])
        # 使用する場合
        dp[i+1][s | c[i]] = min(dp[i+1][s|c[i]], dp[i][s] + a[i]) s range(2**n) range 2**n 2 n dp[i+1][s] = min(dp[i+1][s], dp[i][s]) dp[i+1][s] [i+1] dp i+1 i 1 s min(dp[i+1][s], dp[i][s]) min dp[i+1][s] [i+1] dp i+1 i 1 s dp[i][s] [i] dp i s dp[i+1][s | c[i]] = min(dp[i+1][s|c[i]], dp[i][s] + a[i]) dp[i+1][s | c[i]] [i+1] dp i+1 i 1 s | c[i] s c[i] c i min(dp[i+1][s|c[i]], dp[i][s] + a[i]) min dp[i+1][s|c[i]] [i+1] dp i+1 i 1 s|c[i] s c[i] c i dp[i][s] + a[i] dp[i][s] [i] dp i s a[i] a i print(dp[m][2**n-1]) print dp[m][2**n-1] [m] dp m 2**n-1 2**n 2 n 1 bi = map(int, input().split()) map(int, input().split()) bi ci_int += 2**hako 2**hako ci_int ci = list(map(int, input().split())) list(map(int, input().split())) ci a = [] [] a c = [] [] c hako -= 1 1 hako b = [] [] b ai, bi = map(int, input().split()) map(int, input().split()) ai dp = [[float("inf")]*(2**n) for _ in range(m+1)] [[float("inf")]*(2**n) for _ in range(m+1)] dp n, m = map(int, input().split()) map(int, input().split()) n checker = [0]*n [0]*n checker m = map(int, input().split()) map(int, input().split()) m ci_int = 0 0 ci_int
n, m = map(int, input().split())
a = []
b = []
c = []
checker = [0]*n
for _ in range(m):
    ai, bi = map(int, input().split())
    ci = list(map(int, input().split()))
    ci_int = 0
    for hako in ci:
        hako -= 1
        ci_int += 2**hako
        if checker[hako] == 0:
            checker[hako] = 1
    a.append(ai)
    b.append(bi)
    c.append(ci_int)
#print(a)
#print(b)
#print(c)
if sum(checker) != n:
    print(-1)
    exit()

dp = [[float("inf")]*(2**n) for _ in range(m+1)]
#dp[i][S]はi番目までのカギをいくつか使ってSになるようなコストの最小値
#Sは2進数で表現できる。例）１と３の箱が開けられる状態->0b101
dp[0][0] = 0
for i in range(m):
    for s in range(2**n):
        # i番目のカギを使用しない場合
        dp[i+1][s] = min(dp[i+1][s], dp[i][s])
        # 使用する場合
        dp[i+1][s | c[i]] = min(dp[i+1][s|c[i]], dp[i][s] + a[i])
print(dp[m][2**n-1])