
n, m = map(int, input().split())
ab = []
c= []
keys = ["" for _ in range(m)]

for i in range(m):
    ab.append(list(map(int, input().split())))
    kari = list(map(int, input().split()))
    c.append(kari)
    for j in range(n):
        if j+1 in kari:
            keys[i] = keys[i]+"1"
        else:
            keys[i] = keys[i] + "0"

all_patterns = ["0","1"]
options = ["0", "1"]

for _ in range(n-1):
    all_patterns = [j+i for i in (options) for j in all_patterns]

dp = [1e+10 for i in range(2**n)]
dp[0] = 0

#%%
for j in range(m):
    for i in range(len(dp)):
        kari1 = dp[i]+ab[j][0]
        kari2 = dp[i|int(keys[j],2)]
        if kari1 < kari2:
            dp[i|int(keys[j],2)] = kari1

if dp[-1] != 1e+10:
    print(dp[-1])
else:
    print(-1) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m ab = [] ab [] c= [] c [] "" for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) "" keys = ["" for _ in range(m)] keys ["" for _ in range(m)] for i in range(m):
    ab.append(list(map(int, input().split())))
    kari = list(map(int, input().split()))
    c.append(kari)
    for j in range(n):
        if j+1 in kari:
            keys[i] = keys[i]+"1"
        else:
            keys[i] = keys[i] + "0" i range(m) range m ab.append(list(map(int, input().split()))) ab.append ab append list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split kari = list(map(int, input().split())) kari list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split c.append(kari) c.append c append kari for j in range(n):
        if j+1 in kari:
            keys[i] = keys[i]+"1"
        else:
            keys[i] = keys[i] + "0" j range(n) range n if j+1 in kari:
            keys[i] = keys[i]+"1"
        else:
            keys[i] = keys[i] + "0" j+1 in kari j+1 j 1 kari keys[i] = keys[i]+"1" keys[i] keys i keys[i]+"1" keys[i] keys i "1" keys[i] = keys[i] + "0" keys[i] keys i keys[i] + "0" keys[i] keys i "0" all_patterns = ["0","1"] all_patterns ["0","1"] "0" "1" options = ["0", "1"] options ["0", "1"] "0" "1" for _ in range(n-1):
    all_patterns = [j+i for i in (options) for j in all_patterns] _ range(n-1) range n-1 n 1 j+i for i in (options) for j in all_patterns for i in (options) for j in all_patterns i options for j in all_patterns j all_patterns for j in all_patterns j+i j i all_patterns = [j+i for i in (options) for j in all_patterns] all_patterns [j+i for i in (options) for j in all_patterns] 1e+10 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) 1e+10 dp = [1e+10 for i in range(2**n)] dp [1e+10 for i in range(2**n)] dp[0] = 0 dp[0] dp 0 0 for j in range(m):
    for i in range(len(dp)):
        kari1 = dp[i]+ab[j][0]
        kari2 = dp[i|int(keys[j],2)]
        if kari1 < kari2:
            dp[i|int(keys[j],2)] = kari1 j range(m) range m for i in range(len(dp)):
        kari1 = dp[i]+ab[j][0]
        kari2 = dp[i|int(keys[j],2)]
        if kari1 < kari2:
            dp[i|int(keys[j],2)] = kari1 i range(len(dp)) range len(dp) len dp kari1 = dp[i]+ab[j][0] kari1 dp[i]+ab[j][0] dp[i] dp i ab[j][0] [j] ab j 0 kari2 = dp[i|int(keys[j],2)] kari2 dp[i|int(keys[j],2)] dp i|int(keys[j],2) i int(keys[j],2) int keys[j] keys j 2 if kari1 < kari2:
            dp[i|int(keys[j],2)] = kari1 kari1 < kari2 kari1 kari2 dp[i|int(keys[j],2)] = kari1 dp[i|int(keys[j],2)] dp i|int(keys[j],2) i int(keys[j],2) int keys[j] keys j 2 kari1 if dp[-1] != 1e+10:
    print(dp[-1])
else:
    print(-1) dp[-1] != 1e+10 dp[-1] dp -1 1e+10 print(dp[-1]) print dp[-1] dp -1 print(-1) print -1 n, m = map(int, input().split()) map(int, input().split()) n kari1 = dp[i]+ab[j][0] dp[i]+ab[j][0] kari1 dp = [1e+10 for i in range(2**n)] [1e+10 for i in range(2**n)] dp all_patterns = ["0","1"] ["0","1"] all_patterns ab = [] [] ab m = map(int, input().split()) map(int, input().split()) m kari = list(map(int, input().split())) list(map(int, input().split())) kari kari2 = dp[i|int(keys[j],2)] dp[i|int(keys[j],2)] kari2 options = ["0", "1"] ["0", "1"] options c= [] [] c keys = ["" for _ in range(m)] ["" for _ in range(m)] keys all_patterns = [j+i for i in (options) for j in all_patterns] [j+i for i in (options) for j in all_patterns] all_patterns

n, m = map(int, input().split())
ab = []
c= []
keys = ["" for _ in range(m)]

for i in range(m):
    ab.append(list(map(int, input().split())))
    kari = list(map(int, input().split()))
    c.append(kari)
    for j in range(n):
        if j+1 in kari:
            keys[i] = keys[i]+"1"
        else:
            keys[i] = keys[i] + "0"

all_patterns = ["0","1"]
options = ["0", "1"]

for _ in range(n-1):
    all_patterns = [j+i for i in (options) for j in all_patterns]

dp = [1e+10 for i in range(2**n)]
dp[0] = 0

#%%
for j in range(m):
    for i in range(len(dp)):
        kari1 = dp[i]+ab[j][0]
        kari2 = dp[i|int(keys[j],2)]
        if kari1 < kari2:
            dp[i|int(keys[j],2)] = kari1

if dp[-1] != 1e+10:
    print(dp[-1])
else:
    print(-1)