INF = 10**9

N, M = map(int, input().split())
key = []
for _ in range(M):
    ab = list(map(int, input().split()))
    box = list(map(int, input().split()))
    index = sum(list(map(lambda x:2**(x-1), box)))
    ab.append(index)
    key.append(ab)
dp = [[key[0][0] if (i & ~key[0][2]) == 0 else INF for i in range(2**N)]]
dp[0][0] = 0
for j in range(1, M):
    next = [0 for _ in range(2**N)]
    for i in range(2**N):
        next[i] = min(dp[j-1][i], dp[j-1][(i & ~key[j][2])]+key[j][0])
    dp.append(next)
if dp[-1][-1] > 10**7:
    print(-1)
else:
    print(dp[-1][-1])
 INF = 10**9 INF 10**9 10 9 N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M key = [] key [] for _ in range(M):
    ab = list(map(int, input().split()))
    box = list(map(int, input().split()))
    index = sum(list(map(lambda x:2**(x-1), box)))
    ab.append(index)
    key.append(ab) _ range(M) range M ab = list(map(int, input().split())) ab list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split box = list(map(int, input().split())) box list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split index = sum(list(map(lambda x:2**(x-1), box))) index sum(list(map(lambda x:2**(x-1), box))) sum list(map(lambda x:2**(x-1), box)) list map(lambda x:2**(x-1), box) map lambda x:2**(x-1) 2**(x-1) 2 x-1 x 1 x box ab.append(index) ab.append ab append index key.append(ab) key.append key append ab key[0][0] if (i & ~key[0][2]) == 0 else INF for i in range(2**N) for i in range(2**N) i range(2**N) range 2**N 2 N for i in range(2**N) key[0][0] if (i & ~key[0][2]) == 0 else INF (i & ~key[0][2]) == 0 i & ~key[0][2] i ~key[0][2] key[0][2] [0] key 0 2 0 key[0][0] [0] key 0 0 INF dp = [[key[0][0] if (i & ~key[0][2]) == 0 else INF for i in range(2**N)]] dp [[key[0][0] if (i & ~key[0][2]) == 0 else INF for i in range(2**N)]] [key[0][0] if (i & ~key[0][2]) == 0 else INF for i in range(2**N)] dp[0][0] = 0 dp[0][0] [0] dp 0 0 0 for j in range(1, M):
    next = [0 for _ in range(2**N)]
    for i in range(2**N):
        next[i] = min(dp[j-1][i], dp[j-1][(i & ~key[j][2])]+key[j][0])
    dp.append(next) j range(1, M) range 1 M 0 for _ in range(2**N) for _ in range(2**N) _ range(2**N) range 2**N 2 N for _ in range(2**N) 0 next = [0 for _ in range(2**N)] next [0 for _ in range(2**N)] for i in range(2**N):
        next[i] = min(dp[j-1][i], dp[j-1][(i & ~key[j][2])]+key[j][0])
     i range(2**N) range 2**N 2 N next[i] = min(dp[j-1][i], dp[j-1][(i & ~key[j][2])]+key[j][0]) next[i] next i min(dp[j-1][i], dp[j-1][(i & ~key[j][2])]+key[j][0]) min dp[j-1][i] [j-1] dp j-1 j 1 i dp[j-1][(i & ~key[j][2])]+key[j][0] dp[j-1][(i & ~key[j][2])] [j-1] dp j-1 j 1 i & ~key[j][2] i ~key[j][2] key[j][2] [j] key j 2 key[j][0] [j] key j 0 dp.append(next) dp.append dp append next if dp[-1][-1] > 10**7:
    print(-1)
else:
    print(dp[-1][-1]) dp[-1][-1] > 10**7 dp[-1][-1] [-1] dp -1 -1 10**7 10 7 print(-1) print -1 print(dp[-1][-1]) print dp[-1][-1] [-1] dp -1 -1 next = [0 for _ in range(2**N)] [0 for _ in range(2**N)] next dp = [[key[0][0] if (i & ~key[0][2]) == 0 else INF for i in range(2**N)]] [[key[0][0] if (i & ~key[0][2]) == 0 else INF for i in range(2**N)]] dp box = list(map(int, input().split())) list(map(int, input().split())) box N, M = map(int, input().split()) map(int, input().split()) N ab = list(map(int, input().split())) list(map(int, input().split())) ab key = [] [] key index = sum(list(map(lambda x:2**(x-1), box))) sum(list(map(lambda x:2**(x-1), box))) index M = map(int, input().split()) map(int, input().split()) M INF = 10**9 10**9 INF
INF = 10**9

N, M = map(int, input().split())
key = []
for _ in range(M):
    ab = list(map(int, input().split()))
    box = list(map(int, input().split()))
    index = sum(list(map(lambda x:2**(x-1), box)))
    ab.append(index)
    key.append(ab)
dp = [[key[0][0] if (i & ~key[0][2]) == 0 else INF for i in range(2**N)]]
dp[0][0] = 0
for j in range(1, M):
    next = [0 for _ in range(2**N)]
    for i in range(2**N):
        next[i] = min(dp[j-1][i], dp[j-1][(i & ~key[j][2])]+key[j][0])
    dp.append(next)
if dp[-1][-1] > 10**7:
    print(-1)
else:
    print(dp[-1][-1])

