import sys

input = sys.stdin.readline

n, m = list(map(int, input().split()))

l = [None] * m

li = [None] * m

for i in range(m):

    l[i] = list(map(int, input().split()))

    li[i] = list(map(int, input().split()))

dp = [[float('inf')] * (2 ** n) for _ in range(m + 1)]

dp[0][0] = 0

for i in range(m):

    for j in range(2 ** n):

        if dp[i][j] == float('inf'):

            continue

        tmp = j

        for x in li[i]:

            tmp |= 2 ** (x - 1)

        dp[i + 1][tmp] = min(dp[i + 1][j | tmp], dp[i][j] + l[i][0])

        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

res = dp[m][2 ** n - 1]

if res == float('inf'):

    print((-1))

else:

    print(res)

INF = 10 ** 10

n, m = list(map(int, input().split()))

dp = [[INF] * (2 ** n) for _ in range(m + 1)]

a = [0] * m

c = [0] * m

for i in range(m):

    a[i], b = list(map(int, input().split()))

    t = 0

    for k in list(map(int, input().split())):

        t += 1 << (k - 1)

    c[i] = t

dp[0][0] = 0

for i in range(m):

    for j in range(2 ** n):

        dp[i + 1][j | c[i]] = min(dp[i + 1][j | c[i]], dp[i][j] + a[i])

        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

ans = dp[m][(1 << n) - 1]

if ans == INF:

    print((-1))

else:

    print(ans)

import sys

input = sys.stdin.readline
n, m = list(map(int, input().split()))
l = [None] * m
li = [None] * m
for i in range(m):
    l[i] = list(map(int, input().split()))
    li[i] = list(map(int, input().split()))
dp = [[float("inf")] * (2**n) for _ in range(m + 1)]
dp[0][0] = 0
for i in range(m):
    for j in range(2**n):
        if dp[i][j] == float("inf"):
            continue
        tmp = j
        for x in li[i]:
            tmp |= 2 ** (x - 1)
        dp[i + 1][tmp] = min(dp[i + 1][j | tmp], dp[i][j] + l[i][0])
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
res = dp[m][2**n - 1]
if res == float("inf"):
    print((-1))
else:
    print(res)

INF = 10**10
n, m = list(map(int, input().split()))
dp = [[INF] * (2**n) for _ in range(m + 1)]
a = [0] * m
c = [0] * m
for i in range(m):
    a[i], b = list(map(int, input().split()))
    t = 0
    for k in list(map(int, input().split())):
        t += 1 << (k - 1)
    c[i] = t
dp[0][0] = 0
for i in range(m):
    for j in range(2**n):
        dp[i + 1][j | c[i]] = min(dp[i + 1][j | c[i]], dp[i][j] + a[i])
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
ans = dp[m][(1 << n) - 1]
if ans == INF:
    print((-1))
else:
    print(ans)

-import sys - -input = sys.stdin.readline +INF = 10**10 -l = [None] * m -li = [None] * m +dp = [[INF] * (2**n) for _ in range(m + 1)] +a = [0] * m +c = [0] * m -    l[i] = list(map(int, input().split())) -    li[i] = list(map(int, input().split())) -dp = [[float("inf")] * (2**n) for _ in range(m + 1)] +    a[i], b = list(map(int, input().split())) +    t = 0 +    for k in list(map(int, input().split())): +        t += 1 << (k - 1) +    c[i] = t -        if dp[i][j] == float("inf"): -            continue -        tmp = j -        for x in li[i]: -            tmp |= 2 ** (x - 1) -        dp[i + 1][tmp] = min(dp[i + 1][j | tmp], dp[i][j] + l[i][0]) +        dp[i + 1][j | c[i]] = min(dp[i + 1][j | c[i]], dp[i][j] + a[i]) -res = dp[m][2**n - 1] -if res == float("inf"): +ans = dp[m][(1 << n) - 1] +if ans == INF: -    print(res) +    print(ans)