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