Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
a, b, c = [], [], []
for _ in range(M):
    a_, b_ = map(int, input().split())
    c_ = list( map(int, input().split()) )
    a.append(a_)
    b.append(b_)
    c.append(c_)

exist = [0, 1]
box = set([ i for i in range( 1, N+1 ) ])
minCost = 10**9
for key in range( 1, (1<<M)+1 ):
    openBox = set([])
    price = 0
    for i in range(M):
        if ((key>>i) & 1)==1:
            openBox |= set(c[i])
            price += a[i]
            if price > minCost: continue
    if openBox == box and price <= minCost:
        minCost = price

res = minCost if minCost < 10**9 else -1
print(res)

Fixed submission:
N, M = map(int, input().split())
a, b, c = [], [], []
for _ in range(M):
    a_, b_ = map(int, input().split())
    c_ = list( map(int, input().split()) )
    a.append(a_)
    b.append(b_)
    c.append(c_)

INF = 10**9
bit_dp = [INF for _ in range(2**N)]
bit_dp[0] = 0
for i in range(M):
    bit_n = 0
    for j in c[i]:
        bit_n |=  1 << j - 1
    for j in range(2**N):
        if bit_dp[j|bit_n] > bit_dp[j] + a[i]:
            bit_dp[j|bit_n] = bit_dp[j] + a[i]

res = -1 if bit_dp[-1] >= INF else bit_dp[-1]
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations
N, M = map(int, input().split())
a, b, c = [], [], []
for _ in range(M):
    a_, b_ = map(int, input().split())
    c_ = list( map(int, input().split()) )
    a.append(a_)
    b.append(b_)
    c.append(c_)

exist = [0, 1]
box = set([ i for i in range( 1, N+1 ) ])
minCost = 10**9
for key in range( 1, (1<<M)+1 ):
    openBox = set([])
    price = 0
    for i in range(M):
        if ((key>>i) & 1)==1:
            openBox |= set(c[i])
            price += a[i]
    if openBox == box and price <= minCost:
        minCost = price

res = minCost if minCost < 10**9 else -1
print(res)

Fixed submission:
N, M = map(int, input().split())
a, b, c = [], [], []
for _ in range(M):
    a_, b_ = map(int, input().split())
    c_ = list( map(int, input().split()) )
    a.append(a_)
    b.append(b_)
    c.append(c_)

INF = 10**9
bit_dp = [INF for _ in range(2**N)]
bit_dp[0] = 0
for i in range(M):
    bit_n = 0
    for j in c[i]:
        bit_n |=  1 << j - 1
    for j in range(2**N):
        if bit_dp[j|bit_n] > bit_dp[j] + a[i]:
            bit_dp[j|bit_n] = bit_dp[j] + a[i]

res = -1 if bit_dp[-1] >= INF else bit_dp[-1]
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations
N, M = map(int, input().split())
a, b, c = [], [], []
for _ in range(M):
    a_, b_ = map(int, input().split())
    c_ = list( map(int, input().split()) )
    a.append(a_)
    b.append(b_)
    c.append(c_)

exist = [0, 1]
box = set([ i for i in range( 1, N+1 ) ])
minCost = 10**9
for key in range( 1, (1<<M)+1 ):
    openBox = set([])
    price = 0
    for i in range(M):
        if ((key>>i) & 1)==1:
            openBox |= set(c[i])
            price += a[i]
    if openBox == box and price <= minCost:
        minCost = price

res = minCost if minCost < 10**9 else -1
print(res)

Fixed submission:
N, M = map(int, input().split())
a, b, c = [], [], []
for _ in range(M):
    a_, b_ = map(int, input().split())
    c_ = list( map(int, input().split()) )
    a.append(a_)
    b.append(b_)
    c.append(c_)

INF = 10**9
bit_dp = [INF for _ in range(2**N)]
bit_dp[0] = 0
for i in range(M):
    bit_n = 0
    for j in c[i]:
        bit_n |=  1 << j - 1
    for j in range(2**N):
        if bit_dp[j|bit_n] > bit_dp[j] + a[i]:
            bit_dp[j|bit_n] = bit_dp[j] + a[i]

res = -1 if bit_dp[-1] >= INF else bit_dp[-1]
print(res)