N,M=list(map(int,input().split()))

keys=[[] for _ in range(N)]
dp=[-1]*(2**N)
dp[0]=0

for _ in range(M):
    a,b=list(map(int,input().split()))
    c=list(map(int,input().split()))

    op=2**N-1

    for cc in c:
        op-=2**(cc-1)

    for cc in c:
        keys[cc-1].append((op,a))


def rec(current):
    if dp[current]>-1:
        return dp[current]

    ret=10**10

    i=0
    tmp=current
    while tmp&1==0:
        i+=1
        tmp=tmp>>1
    
    for op,a in keys[i]:
        minc=rec(current&op)
        ret=min(ret,a+minc)
    
    if ret==10**10:
        print(-1)
        exit(0)
    
    dp[current]=ret
    return ret

print(rec(2**N-1)) N,M=list(map(int,input().split())) N list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split M [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] keys=[[] for _ in range(N)] keys [[] for _ in range(N)] dp=[-1]*(2**N) dp [-1]*(2**N) [-1] -1 2**N 2 N dp[0]=0 dp[0] dp 0 0 for _ in range(M):
    a,b=list(map(int,input().split()))
    c=list(map(int,input().split()))

    op=2**N-1

    for cc in c:
        op-=2**(cc-1)

    for cc in c:
        keys[cc-1].append((op,a)) _ range(M) range M a,b=list(map(int,input().split())) a list(map(int,input().split())) list 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 op=2**N-1 op 2**N-1 2**N 2 N 1 for cc in c:
        op-=2**(cc-1)

     cc c op-=2**(cc-1) op 2**(cc-1) 2 cc-1 cc 1 for cc in c:
        keys[cc-1].append((op,a)) cc c keys[cc-1].append((op,a)) [cc-1].append [cc-1] keys cc-1 cc 1 append (op,a) op a def rec(current):
    if dp[current]>-1:
        return dp[current]

    ret=10**10

    i=0
    tmp=current
    while tmp&1==0:
        i+=1
        tmp=tmp>>1
    
    for op,a in keys[i]:
        minc=rec(current&op)
        ret=min(ret,a+minc)
    
    if ret==10**10:
        print(-1)
        exit(0)
    
    dp[current]=ret
    return ret rec if dp[current]>-1:
        return dp[current]

     dp[current]>-1 dp[current] dp current -1 return dp[current] dp[current] dp current ret=10**10 ret 10**10 10 10 i=0 i 0 tmp=current tmp current while tmp&1==0:
        i+=1
        tmp=tmp>>1
    
     tmp&1==0 tmp&1 tmp 1 0 i+=1 i 1 tmp=tmp>>1 tmp tmp>>1 tmp 1 for op,a in keys[i]:
        minc=rec(current&op)
        ret=min(ret,a+minc)
    
     op a keys[i] keys i minc=rec(current&op) minc rec(current&op) rec current&op current op ret=min(ret,a+minc) ret min(ret,a+minc) min ret a+minc a minc if ret==10**10:
        print(-1)
        exit(0)
    
     ret==10**10 ret 10**10 10 10 print(-1) print -1 exit(0) exit 0 dp[current]=ret dp[current] dp current ret return ret ret current current print(rec(2**N-1)) print rec(2**N-1) rec 2**N-1 2**N 2 N 1 keys=[[] for _ in range(N)] [[] for _ in range(N)] keys a,b=list(map(int,input().split())) list(map(int,input().split())) a dp=[-1]*(2**N) [-1]*(2**N) dp b=list(map(int,input().split())) list(map(int,input().split())) b c=list(map(int,input().split())) list(map(int,input().split())) c N,M=list(map(int,input().split())) list(map(int,input().split())) N op=2**N-1 2**N-1 op def rec(current):
    if dp[current]>-1:
        return dp[current]

    ret=10**10

    i=0
    tmp=current
    while tmp&1==0:
        i+=1
        tmp=tmp>>1
    
    for op,a in keys[i]:
        minc=rec(current&op)
        ret=min(ret,a+minc)
    
    if ret==10**10:
        print(-1)
        exit(0)
    
    dp[current]=ret
    return ret def rec(current):
    if dp[current]>-1:
        return dp[current]

    ret=10**10

    i=0
    tmp=current
    while tmp&1==0:
        i+=1
        tmp=tmp>>1
    
    for op,a in keys[i]:
        minc=rec(current&op)
        ret=min(ret,a+minc)
    
    if ret==10**10:
        print(-1)
        exit(0)
    
    dp[current]=ret
    return ret rec M=list(map(int,input().split())) list(map(int,input().split())) M op-=2**(cc-1) 2**(cc-1) op
N,M=list(map(int,input().split()))

keys=[[] for _ in range(N)]
dp=[-1]*(2**N)
dp[0]=0

for _ in range(M):
    a,b=list(map(int,input().split()))
    c=list(map(int,input().split()))

    op=2**N-1

    for cc in c:
        op-=2**(cc-1)

    for cc in c:
        keys[cc-1].append((op,a))


def rec(current):
    if dp[current]>-1:
        return dp[current]

    ret=10**10

    i=0
    tmp=current
    while tmp&1==0:
        i+=1
        tmp=tmp>>1
    
    for op,a in keys[i]:
        minc=rec(current&op)
        ret=min(ret,a+minc)
    
    if ret==10**10:
        print(-1)
        exit(0)
    
    dp[current]=ret
    return ret

print(rec(2**N-1))