N,M=map(int,input().split())
price_value = []
for _ in range(M):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    v = ["0"]*N
    for i in range(N):
        if i+1 in c:
            v[i] = "1"
    v = "".join(v)
    v = int(v, base=2)
    price_value.append((a, v))

INF = float("inf")
dp = [[INF] * (2**N) for _ in range(M+1)]
dp[0][0] = 0
for i in range(1, M+1):
    price, value = price_value[i-1]
    for j in range(2**N):
        dp[i][j | value] = min(
            dp[i][j | value], dp[i-1][j] + price
        )
        dp[i][j] = min(dp[i][j], dp[i-1][j])
ans = dp[-1][-1]
print(ans if ans != INF else -1) N,M=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M price_value = [] price_value [] for _ in range(M):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    v = ["0"]*N
    for i in range(N):
        if i+1 in c:
            v[i] = "1"
    v = "".join(v)
    v = int(v, base=2)
    price_value.append((a, v)) _ range(M) range M a, b = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b c = list(map(int, input().split())) c list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split v = ["0"]*N v ["0"]*N ["0"] "0" N for i in range(N):
        if i+1 in c:
            v[i] = "1"
     i range(N) range N if i+1 in c:
            v[i] = "1"
     i+1 in c i+1 i 1 c v[i] = "1" v[i] v i "1" v = "".join(v) v "".join(v) "".join "" join v v = int(v, base=2) v int(v, base=2) int v base=2 base 2 price_value.append((a, v)) price_value.append price_value append (a, v) a v INF = float("inf") INF float("inf") float "inf" [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) [INF] * (2**N) [INF] INF 2**N 2 N dp = [[INF] * (2**N) for _ in range(M+1)] dp [[INF] * (2**N) for _ in range(M+1)] dp[0][0] = 0 dp[0][0] [0] dp 0 0 0 for i in range(1, M+1):
    price, value = price_value[i-1]
    for j in range(2**N):
        dp[i][j | value] = min(
            dp[i][j | value], dp[i-1][j] + price
        )
        dp[i][j] = min(dp[i][j], dp[i-1][j]) i range(1, M+1) range 1 M+1 M 1 price, value = price_value[i-1] price price_value[i-1] price_value i-1 i 1 value for j in range(2**N):
        dp[i][j | value] = min(
            dp[i][j | value], dp[i-1][j] + price
        )
        dp[i][j] = min(dp[i][j], dp[i-1][j]) j range(2**N) range 2**N 2 N dp[i][j | value] = min(
            dp[i][j | value], dp[i-1][j] + price
        ) dp[i][j | value] [i] dp i j | value j value min(
            dp[i][j | value], dp[i-1][j] + price
        ) min dp[i][j | value] [i] dp i j | value j value dp[i-1][j] + price dp[i-1][j] [i-1] dp i-1 i 1 j price dp[i][j] = min(dp[i][j], dp[i-1][j]) dp[i][j] [i] dp i j min(dp[i][j], dp[i-1][j]) min dp[i][j] [i] dp i j dp[i-1][j] [i-1] dp i-1 i 1 j ans = dp[-1][-1] ans dp[-1][-1] [-1] dp -1 -1 print(ans if ans != INF else -1) print ans if ans != INF else -1 ans != INF ans INF ans -1 value = price_value[i-1] price_value[i-1] value N,M=map(int,input().split()) map(int,input().split()) N v = ["0"]*N ["0"]*N v v = int(v, base=2) int(v, base=2) v a, b = map(int, input().split()) map(int, input().split()) a v = "".join(v) "".join(v) v b = map(int, input().split()) map(int, input().split()) b dp = [[INF] * (2**N) for _ in range(M+1)] [[INF] * (2**N) for _ in range(M+1)] dp INF = float("inf") float("inf") INF price, value = price_value[i-1] price_value[i-1] price c = list(map(int, input().split())) list(map(int, input().split())) c price_value = [] [] price_value M=map(int,input().split()) map(int,input().split()) M ans = dp[-1][-1] dp[-1][-1] ans
N,M=map(int,input().split())
price_value = []
for _ in range(M):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    v = ["0"]*N
    for i in range(N):
        if i+1 in c:
            v[i] = "1"
    v = "".join(v)
    v = int(v, base=2)
    price_value.append((a, v))

INF = float("inf")
dp = [[INF] * (2**N) for _ in range(M+1)]
dp[0][0] = 0
for i in range(1, M+1):
    price, value = price_value[i-1]
    for j in range(2**N):
        dp[i][j | value] = min(
            dp[i][j | value], dp[i-1][j] + price
        )
        dp[i][j] = min(dp[i][j], dp[i-1][j])
ans = dp[-1][-1]
print(ans if ans != INF else -1)