n,m=map(int,input().split())
keys = []
A = [0]*m
for i in range(m):

    a,b=map(int,input().split())
    A[i] = a
    k = 0
    for c in map(int,input().split()):
        k = k| 2**(c-1)
        ## 鍵kがc番目の宝箱を開けられる--> k & 2**(c-1) == 1
    keys.append(k)



dp = [[10**9]*2**n for i in range(m+1)] #dp[i][j] iまで使って状態jを実現する最小コスト
dp[-1][0] = 0
for i in range(m):
    a = A[i]
    k = keys[i]
    for j in range(2**n):
        dp[i][j|k] = min(dp[i-1][j|k],dp[i-1][j]+a,dp[i][j|k])
        ## j|k -->jにkを使って開けられる宝箱の種類
        ## 前のまま(dp[i][j|k]) or jに鍵を使う(dp[i-1][j]+a)
        dp[i][j] = min(dp[i][j],dp[i-1][j]) # 鍵を使わない場合の更新
ans = dp[m-1][2**n-1]
if ans ==10**9:
    print(-1)
else:
    print(ans) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m keys = [] keys [] A = [0]*m A [0]*m [0] 0 m for i in range(m):

    a,b=map(int,input().split())
    A[i] = a
    k = 0
    for c in map(int,input().split()):
        k = k| 2**(c-1)
        ## 鍵kがc番目の宝箱を開けられる--> k & 2**(c-1) == 1
    keys.append(k) i range(m) range m a,b=map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b A[i] = a A[i] A i a k = 0 k 0 for c in map(int,input().split()):
        k = k| 2**(c-1)
        ## 鍵kがc番目の宝箱を開けられる--> k & 2**(c-1) == 1
     c map(int,input().split()) map int input().split() ().split () input split k = k| 2**(c-1) k k| 2**(c-1) k 2**(c-1) 2 c-1 c 1 keys.append(k) keys.append keys append k [10**9]*2**n for i in range(m+1) for i in range(m+1) i range(m+1) range m+1 m 1 for i in range(m+1) [10**9]*2**n [10**9] 10**9 10 9 2**n 2 n dp = [[10**9]*2**n for i in range(m+1)] dp [[10**9]*2**n for i in range(m+1)] dp[-1][0] = 0 dp[-1][0] [-1] dp -1 0 0 for i in range(m):
    a = A[i]
    k = keys[i]
    for j in range(2**n):
        dp[i][j|k] = min(dp[i-1][j|k],dp[i-1][j]+a,dp[i][j|k])
        ## j|k -->jにkを使って開けられる宝箱の種類
        ## 前のまま(dp[i][j|k]) or jに鍵を使う(dp[i-1][j]+a)
        dp[i][j] = min(dp[i][j],dp[i-1][j]) # 鍵を使わない場合の更新 i range(m) range m a = A[i] a A[i] A i k = keys[i] k keys[i] keys i for j in range(2**n):
        dp[i][j|k] = min(dp[i-1][j|k],dp[i-1][j]+a,dp[i][j|k])
        ## j|k -->jにkを使って開けられる宝箱の種類
        ## 前のまま(dp[i][j|k]) or jに鍵を使う(dp[i-1][j]+a)
        dp[i][j] = min(dp[i][j],dp[i-1][j]) # 鍵を使わない場合の更新 j range(2**n) range 2**n 2 n dp[i][j|k] = min(dp[i-1][j|k],dp[i-1][j]+a,dp[i][j|k]) dp[i][j|k] [i] dp i j|k j k min(dp[i-1][j|k],dp[i-1][j]+a,dp[i][j|k]) min dp[i-1][j|k] [i-1] dp i-1 i 1 j|k j k dp[i-1][j]+a dp[i-1][j] [i-1] dp i-1 i 1 j a dp[i][j|k] [i] dp i j|k j k 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[m-1][2**n-1] ans dp[m-1][2**n-1] [m-1] dp m-1 m 1 2**n-1 2**n 2 n 1 if ans ==10**9:
    print(-1)
else:
    print(ans) ans ==10**9 ans 10**9 10 9 print(-1) print -1 print(ans) print ans a,b=map(int,input().split()) map(int,input().split()) a b=map(int,input().split()) map(int,input().split()) b k = k| 2**(c-1) k| 2**(c-1) k ans = dp[m-1][2**n-1] dp[m-1][2**n-1] ans m=map(int,input().split()) map(int,input().split()) m a = A[i] A[i] a k = 0 0 k dp = [[10**9]*2**n for i in range(m+1)] [[10**9]*2**n for i in range(m+1)] dp keys = [] [] keys n,m=map(int,input().split()) map(int,input().split()) n k = keys[i] keys[i] k A = [0]*m [0]*m A
n,m=map(int,input().split())
keys = []
A = [0]*m
for i in range(m):

    a,b=map(int,input().split())
    A[i] = a
    k = 0
    for c in map(int,input().split()):
        k = k| 2**(c-1)
        ## 鍵kがc番目の宝箱を開けられる--> k & 2**(c-1) == 1
    keys.append(k)



dp = [[10**9]*2**n for i in range(m+1)] #dp[i][j] iまで使って状態jを実現する最小コスト
dp[-1][0] = 0
for i in range(m):
    a = A[i]
    k = keys[i]
    for j in range(2**n):
        dp[i][j|k] = min(dp[i-1][j|k],dp[i-1][j]+a,dp[i][j|k])
        ## j|k -->jにkを使って開けられる宝箱の種類
        ## 前のまま(dp[i][j|k]) or jに鍵を使う(dp[i-1][j]+a)
        dp[i][j] = min(dp[i][j],dp[i-1][j]) # 鍵を使わない場合の更新
ans = dp[m-1][2**n-1]
if ans ==10**9:
    print(-1)
else:
    print(ans)
