import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = list(map(int, input().split()))
bs = [None]*m
a = [None]*m
for i in range(m):
    a[i],_ = map(int, input().split())
    c = list(map(int, input().split()))
    b = 0
    for num in c:
        b += 1<<(num-1)
    bs[i] = b
dp = [[float("inf")]*(1<<n) for _ in range(m+1)]
for i in range(m+1):
    dp[i][0] = 0
for i in range(m):
    for j in range(1<<n):
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        b = j | bs[i]
        dp[i+1][b] = min(dp[i+1][b], dp[i][j]+a[i])
ans = dp[m][(1<<n)-1]
if ans==float("inf"):
    ans = -1
print(ans) import sys sys input = lambda : sys.stdin.readline().rstrip() input lambda : sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip sys.setrecursionlimit(max(1000, 10**9)) sys.setrecursionlimit sys setrecursionlimit max(1000, 10**9) max 1000 10**9 10 9 write = lambda x: sys.stdout.write(x+"\n") write lambda x: sys.stdout.write(x+"\n") sys.stdout.write(x+"\n") sys.stdout.write sys.stdout sys stdout write x+"\n" x "\n" x 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 bs = [None]*m bs [None]*m [None] None m a = [None]*m a [None]*m [None] None m for i in range(m):
    a[i],_ = map(int, input().split())
    c = list(map(int, input().split()))
    b = 0
    for num in c:
        b += 1<<(num-1)
    bs[i] = b i range(m) range m a[i],_ = map(int, input().split()) a[i] a i map(int, input().split()) map int input().split() ().split () input split _ c = list(map(int, input().split())) c list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split b = 0 b 0 for num in c:
        b += 1<<(num-1)
     num c b += 1<<(num-1) b 1<<(num-1) 1 num-1 num 1 bs[i] = b bs[i] bs i b [float("inf")]*(1<<n) for _ in range(m+1) for _ in range(m+1) _ range(m+1) range m+1 m 1 for _ in range(m+1) [float("inf")]*(1<<n) [float("inf")] float("inf") float "inf" 1<<n 1 n dp = [[float("inf")]*(1<<n) for _ in range(m+1)] dp [[float("inf")]*(1<<n) for _ in range(m+1)] for i in range(m+1):
    dp[i][0] = 0 i range(m+1) range m+1 m 1 dp[i][0] = 0 dp[i][0] [i] dp i 0 0 for i in range(m):
    for j in range(1<<n):
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        b = j | bs[i]
        dp[i+1][b] = min(dp[i+1][b], dp[i][j]+a[i]) i range(m) range m for j in range(1<<n):
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        b = j | bs[i]
        dp[i+1][b] = min(dp[i+1][b], dp[i][j]+a[i]) j range(1<<n) range 1<<n 1 n dp[i+1][j] = min(dp[i+1][j], dp[i][j]) dp[i+1][j] [i+1] dp i+1 i 1 j min(dp[i+1][j], dp[i][j]) min dp[i+1][j] [i+1] dp i+1 i 1 j dp[i][j] [i] dp i j b = j | bs[i] b j | bs[i] j bs[i] bs i dp[i+1][b] = min(dp[i+1][b], dp[i][j]+a[i]) dp[i+1][b] [i+1] dp i+1 i 1 b min(dp[i+1][b], dp[i][j]+a[i]) min dp[i+1][b] [i+1] dp i+1 i 1 b dp[i][j]+a[i] dp[i][j] [i] dp i j a[i] a i ans = dp[m][(1<<n)-1] ans dp[m][(1<<n)-1] [m] dp m (1<<n)-1 1<<n 1 n 1 if ans==float("inf"):
    ans = -1 ans==float("inf") ans float("inf") float "inf" ans = -1 ans -1 print(ans) print ans a = [None]*m [None]*m a b += 1<<(num-1) 1<<(num-1) b bs = [None]*m [None]*m bs c = list(map(int, input().split())) list(map(int, input().split())) c input = lambda : sys.stdin.readline().rstrip() lambda : sys.stdin.readline().rstrip() input dp = [[float("inf")]*(1<<n) for _ in range(m+1)] [[float("inf")]*(1<<n) for _ in range(m+1)] dp n,m = list(map(int, input().split())) list(map(int, input().split())) n _ = map(int, input().split()) map(int, input().split()) _ b = j | bs[i] j | bs[i] b ans = dp[m][(1<<n)-1] dp[m][(1<<n)-1] ans ans = -1 -1 ans write = lambda x: sys.stdout.write(x+"\n") lambda x: sys.stdout.write(x+"\n") write m = list(map(int, input().split())) list(map(int, input().split())) m b = 0 0 b
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = list(map(int, input().split()))
bs = [None]*m
a = [None]*m
for i in range(m):
    a[i],_ = map(int, input().split())
    c = list(map(int, input().split()))
    b = 0
    for num in c:
        b += 1<<(num-1)
    bs[i] = b
dp = [[float("inf")]*(1<<n) for _ in range(m+1)]
for i in range(m+1):
    dp[i][0] = 0
for i in range(m):
    for j in range(1<<n):
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        b = j | bs[i]
        dp[i+1][b] = min(dp[i+1][b], dp[i][j]+a[i])
ans = dp[m][(1<<n)-1]
if ans==float("inf"):
    ans = -1
print(ans)