import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = [0]*M
B = [0]*M
C = [0]*M
for i in range(M):
    A[i], B[i] = map(int, input().split())
    for c in [int(i) for i in input().split()]:
        C[i] |= 1 << (c - 1)

dp = [[float("inf")] * 2 ** N for _ in range(2)]
dp[0][0] = 0
for i, c in enumerate(C):
    for bit in range(2 ** N):
        if c & bit == bit:
            dp[1][bit] = min(dp[1][bit], dp[0][bit], A[i])
        else:
            dp[1][bit] = min(dp[1][bit], dp[0][bit])
        dp[1][c | bit] = min(dp[0][c | bit], dp[0][bit] + A[i], dp[1][c | bit])
    dp[0], dp[1] = dp[1], dp[0]
print(dp[0][-1] if dp[0][-1] < float("inf") else - 1) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = [0]*M A [0]*M [0] 0 M B = [0]*M B [0]*M [0] 0 M C = [0]*M C [0]*M [0] 0 M for i in range(M):
    A[i], B[i] = map(int, input().split())
    for c in [int(i) for i in input().split()]:
        C[i] |= 1 << (c - 1) i range(M) range M A[i], B[i] = map(int, input().split()) A[i] A i map(int, input().split()) map int input().split() ().split () input split B[i] B i for c in [int(i) for i in input().split()]:
        C[i] |= 1 << (c - 1) c [int(i) for i in input().split()] C[i] |= 1 << (c - 1) C[i] C i 1 << (c - 1) 1 c - 1 c 1 [float("inf")] * 2 ** N for _ in range(2) for _ in range(2) _ range(2) range 2 for _ in range(2) [float("inf")] * 2 ** N [float("inf")] float("inf") float "inf" 2 ** N 2 N dp = [[float("inf")] * 2 ** N for _ in range(2)] dp [[float("inf")] * 2 ** N for _ in range(2)] dp[0][0] = 0 dp[0][0] [0] dp 0 0 0 for i, c in enumerate(C):
    for bit in range(2 ** N):
        if c & bit == bit:
            dp[1][bit] = min(dp[1][bit], dp[0][bit], A[i])
        else:
            dp[1][bit] = min(dp[1][bit], dp[0][bit])
        dp[1][c | bit] = min(dp[0][c | bit], dp[0][bit] + A[i], dp[1][c | bit])
    dp[0], dp[1] = dp[1], dp[0] i c enumerate(C) enumerate C for bit in range(2 ** N):
        if c & bit == bit:
            dp[1][bit] = min(dp[1][bit], dp[0][bit], A[i])
        else:
            dp[1][bit] = min(dp[1][bit], dp[0][bit])
        dp[1][c | bit] = min(dp[0][c | bit], dp[0][bit] + A[i], dp[1][c | bit])
     bit range(2 ** N) range 2 ** N 2 N if c & bit == bit:
            dp[1][bit] = min(dp[1][bit], dp[0][bit], A[i])
        else:
            dp[1][bit] = min(dp[1][bit], dp[0][bit])
         c & bit == bit c & bit c bit bit dp[1][bit] = min(dp[1][bit], dp[0][bit], A[i]) dp[1][bit] [1] dp 1 bit min(dp[1][bit], dp[0][bit], A[i]) min dp[1][bit] [1] dp 1 bit dp[0][bit] [0] dp 0 bit A[i] A i dp[1][bit] = min(dp[1][bit], dp[0][bit]) dp[1][bit] [1] dp 1 bit min(dp[1][bit], dp[0][bit]) min dp[1][bit] [1] dp 1 bit dp[0][bit] [0] dp 0 bit dp[1][c | bit] = min(dp[0][c | bit], dp[0][bit] + A[i], dp[1][c | bit]) dp[1][c | bit] [1] dp 1 c | bit c bit min(dp[0][c | bit], dp[0][bit] + A[i], dp[1][c | bit]) min dp[0][c | bit] [0] dp 0 c | bit c bit dp[0][bit] + A[i] dp[0][bit] [0] dp 0 bit A[i] A i dp[1][c | bit] [1] dp 1 c | bit c bit dp[0], dp[1] = dp[1], dp[0] dp[0] dp 0 dp[1] dp 1 dp[1] dp 1 dp[0] dp 0 print(dp[0][-1] if dp[0][-1] < float("inf") else - 1) print dp[0][-1] if dp[0][-1] < float("inf") else - 1 dp[0][-1] < float("inf") dp[0][-1] [0] dp 0 -1 float("inf") float "inf" dp[0][-1] [0] dp 0 -1 - 1 C = [0]*M [0]*M C dp = [[float("inf")] * 2 ** N for _ in range(2)] [[float("inf")] * 2 ** N for _ in range(2)] dp B = [0]*M [0]*M B input = sys.stdin.readline sys.stdin.readline input M = map(int, input().split()) map(int, input().split()) M A = [0]*M [0]*M A N, M = map(int, input().split()) map(int, input().split()) N
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = [0]*M
B = [0]*M
C = [0]*M
for i in range(M):
    A[i], B[i] = map(int, input().split())
    for c in [int(i) for i in input().split()]:
        C[i] |= 1 << (c - 1)

dp = [[float("inf")] * 2 ** N for _ in range(2)]
dp[0][0] = 0
for i, c in enumerate(C):
    for bit in range(2 ** N):
        if c & bit == bit:
            dp[1][bit] = min(dp[1][bit], dp[0][bit], A[i])
        else:
            dp[1][bit] = min(dp[1][bit], dp[0][bit])
        dp[1][c | bit] = min(dp[0][c | bit], dp[0][bit] + A[i], dp[1][c | bit])
    dp[0], dp[1] = dp[1], dp[0]
print(dp[0][-1] if dp[0][-1] < float("inf") else - 1)