from functools import reduce
INF = 10 ** 7
N, M = map(int, input().split())
L = 1 << N
keys = [0] * M
for m 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())))
    keys[m] = cost, match
table = [[INF] * L for _ in range(M + 1)]
table[0][0] = 0
for m in range(M):
    cost, match = keys[m]
    for l in range(L):
        now = table[m][l]
        if l and not now:
            continue
        table[m + 1][l] = min(now, table[m + 1][l])
        table[m + 1][l | match] = min(now + cost, table[m + 1][l | match])
print(table[M][L - 1] if table[M][L - 1] != INF else -1) from functools import reduce INF = 10 ** 7 INF 10 ** 7 10 7 N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L = 1 << N L 1 << N 1 N keys = [0] * M keys [0] * M [0] 0 M for m 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())))
    keys[m] = cost, match m range(M) range M cost, _ = map(int, input().split()) cost map(int, input().split()) map int input().split() ().split () input split _ 1 << shamt for shamt in map(lambda n: int(n) - 1, input().split()) for shamt in map(lambda n: int(n) - 1, input().split()) shamt map(lambda n: int(n) - 1, input().split()) map lambda n: int(n) - 1 int(n) - 1 int(n) int n 1 n input().split() ().split () input split for shamt in map(lambda n: int(n) - 1, input().split()) 1 << shamt 1 shamt match = reduce(lambda a, b: a | b, (1 << shamt for shamt in map(lambda n: int(n) - 1, input().split()))) match reduce(lambda a, b: a | b, (1 << shamt for shamt in map(lambda n: int(n) - 1, input().split()))) reduce lambda a, b: a | b a | b a b a b (1 << shamt for shamt in map(lambda n: int(n) - 1, input().split())) keys[m] = cost, match keys[m] keys m keys[m] = cost, match cost match [INF] * L for _ in range(M + 1) for _ in range(M + 1) _ range(M + 1) range M + 1 M 1 for _ in range(M + 1) [INF] * L [INF] INF L table = [[INF] * L for _ in range(M + 1)] table [[INF] * L for _ in range(M + 1)] table[0][0] = 0 table[0][0] [0] table 0 0 0 for m in range(M):
    cost, match = keys[m]
    for l in range(L):
        now = table[m][l]
        if l and not now:
            continue
        table[m + 1][l] = min(now, table[m + 1][l])
        table[m + 1][l | match] = min(now + cost, table[m + 1][l | match]) m range(M) range M cost, match = keys[m] cost keys[m] keys m match for l in range(L):
        now = table[m][l]
        if l and not now:
            continue
        table[m + 1][l] = min(now, table[m + 1][l])
        table[m + 1][l | match] = min(now + cost, table[m + 1][l | match]) l range(L) range L now = table[m][l] now table[m][l] [m] table m l if l and not now:
            continue
         l and not now l not now now continue table[m + 1][l] = min(now, table[m + 1][l]) table[m + 1][l] [m + 1] table m + 1 m 1 l min(now, table[m + 1][l]) min now table[m + 1][l] [m + 1] table m + 1 m 1 l table[m + 1][l | match] = min(now + cost, table[m + 1][l | match]) table[m + 1][l | match] [m + 1] table m + 1 m 1 l | match l match min(now + cost, table[m + 1][l | match]) min now + cost now cost table[m + 1][l | match] [m + 1] table m + 1 m 1 l | match l match print(table[M][L - 1] if table[M][L - 1] != INF else -1) print table[M][L - 1] if table[M][L - 1] != INF else -1 table[M][L - 1] != INF table[M][L - 1] [M] table M L - 1 L 1 INF table[M][L - 1] [M] table M L - 1 L 1 -1 match = keys[m] keys[m] match L = 1 << N 1 << N L cost, _ = map(int, input().split()) map(int, input().split()) cost match = reduce(lambda a, b: a | b, (1 << shamt for shamt in map(lambda n: int(n) - 1, input().split()))) reduce(lambda a, b: a | b, (1 << shamt for shamt in map(lambda n: int(n) - 1, input().split()))) match N, M = map(int, input().split()) map(int, input().split()) N cost, match = keys[m] keys[m] cost now = table[m][l] table[m][l] now INF = 10 ** 7 10 ** 7 INF M = map(int, input().split()) map(int, input().split()) M keys = [0] * M [0] * M keys _ = map(int, input().split()) map(int, input().split()) _ table = [[INF] * L for _ in range(M + 1)] [[INF] * L for _ in range(M + 1)] table
from functools import reduce
INF = 10 ** 7
N, M = map(int, input().split())
L = 1 << N
keys = [0] * M
for m 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())))
    keys[m] = cost, match
table = [[INF] * L for _ in range(M + 1)]
table[0][0] = 0
for m in range(M):
    cost, match = keys[m]
    for l in range(L):
        now = table[m][l]
        if l and not now:
            continue
        table[m + 1][l] = min(now, table[m + 1][l])
        table[m + 1][l | match] = min(now + cost, table[m + 1][l | match])
print(table[M][L - 1] if table[M][L - 1] != INF else -1)