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



dp = [float("inf")]*(2**n)



p = []

used = [True]*(2**n)



for _ in range(m):

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

    c = tuple(map(int,input().split()))

    jkl = 0

    for e in c:

        jkl += 1 << (e-1)

    p.append(jkl)

    dp[jkl] = min(dp[jkl],a)

    used[jkl] = False



tank = []



while True:

    tank = []

    for e in p:

        for ep in p:

            if dp[e|ep] > dp[e]+dp[ep]:

                dp[e|ep] = dp[e]+dp[ep]

                if used[e|ep]:

                    tank.append(e|ep)

                    used[e|ep] = False



    if len(tank) == 0:

        break

    for e in tank:

        p.append(e)



if dp[-1] == float("inf"):

    print((-1))

else:

    print((dp[-1]))
import sys

input = sys.stdin.readline

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



dp = [float("inf")]*(1<<n)

dp[0] = 0

for _ in [0]*m:

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

    sc = 0

    for e in map(int,input().split()):

        sc += 1<<(e-1)

    

    for i in range(1<<n):

        dp[i|sc] = min(dp[i|sc],dp[i]+a)





if dp[-1] == float("inf"):

    print((-1))

else:

    print((dp[-1]))
n, m = list(map(int, input().split()))
dp = [float("inf")] * (2**n)
p = []
used = [True] * (2**n)
for _ in range(m):
    a, b = list(map(int, input().split()))
    c = tuple(map(int, input().split()))
    jkl = 0
    for e in c:
        jkl += 1 << (e - 1)
    p.append(jkl)
    dp[jkl] = min(dp[jkl], a)
    used[jkl] = False
tank = []
while True:
    tank = []
    for e in p:
        for ep in p:
            if dp[e | ep] > dp[e] + dp[ep]:
                dp[e | ep] = dp[e] + dp[ep]
                if used[e | ep]:
                    tank.append(e | ep)
                    used[e | ep] = False
    if len(tank) == 0:
        break
    for e in tank:
        p.append(e)
if dp[-1] == float("inf"):
    print((-1))
else:
    print((dp[-1]))

import sys

input = sys.stdin.readline
n, m = list(map(int, input().split()))
dp = [float("inf")] * (1 << n)
dp[0] = 0
for _ in [0] * m:
    a, b = list(map(int, input().split()))
    sc = 0
    for e in map(int, input().split()):
        sc += 1 << (e - 1)
    for i in range(1 << n):
        dp[i | sc] = min(dp[i | sc], dp[i] + a)
if dp[-1] == float("inf"):
    print((-1))
else:
    print((dp[-1]))

+import sys + +input = sys.stdin.readline -dp = [float("inf")] * (2**n) -p = [] -used = [True] * (2**n) -for _ in range(m): +dp = [float("inf")] * (1 << n) +dp[0] = 0 +for _ in [0] * m: -    c = tuple(map(int, input().split())) -    jkl = 0 -    for e in c: -        jkl += 1 << (e - 1) -    p.append(jkl) -    dp[jkl] = min(dp[jkl], a) -    used[jkl] = False -tank = [] -while True: -    tank = [] -    for e in p: -        for ep in p: -            if dp[e | ep] > dp[e] + dp[ep]: -                dp[e | ep] = dp[e] + dp[ep] -                if used[e | ep]: -                    tank.append(e | ep) -                    used[e | ep] = False -    if len(tank) == 0: -        break -    for e in tank: -        p.append(e) +    sc = 0 +    for e in map(int, input().split()): +        sc += 1 << (e - 1) +    for i in range(1 << n): +        dp[i | sc] = min(dp[i | sc], dp[i] + a)