Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
keys=[]
inf=12*(10**5)+1
for i in range(M):
    a,b=map(int,input().split())
    c=sum([1<<(i-1) for i in list(map(int,input().split()))])
    keys.append((a,c))

#print(keys)

dp=[inf for j in range(2**N)]
dp[0]=0

for key in keys:
    for j in range(2**N):
        dp[j|key[1]]=min(dp[j|key[1]],dp[j]+key[0])
#    print(dp)

print(dp[2**N-1] if dp[2**N-1]!=inf else -1)

Fixed submission:
N,M=map(int,input().split())
inf=12*(10**5)+1

dp=[inf for j in range(2**N)]
dp[0]=0

for i in range(M):
    a,b=map(int,input().split())
    c=sum([1<<(i-1) for i in list(map(int,input().split()))])
#    print(a,b,c)
    for j in range(2**N):
        dp[j|c]=min(dp[j|c],dp[j]+a)
#    print(dp)

print(dp[2**N-1] if dp[2**N-1]!=inf else -1)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
keys=[]
for i in range(M):
    a,b=map(int,input().split())
    c=list(map(int,input().split()))
    cans=0
    for i in c:
        cans+=1<<(i-1)
    keys.append((a,cans))

#print(keys)

dp=[12*(10**5)+1 for j in range(2**N)]
dp[0]=0

for key in keys:
    for j in range(2**N):
        dp[j|key[1]]=min(dp[j|key[1]],dp[j]+key[0])
#    print(dp)

print(dp[2**N-1] if dp[2**N-1]!=12*(10**5)+1 else -1)

Fixed submission:
N,M=map(int,input().split())
inf=12*(10**5)+1

dp=[inf for j in range(2**N)]
dp[0]=0

for i in range(M):
    a,b=map(int,input().split())
    c=sum([1<<(i-1) for i in list(map(int,input().split()))])
#    print(a,b,c)
    for j in range(2**N):
        dp[j|c]=min(dp[j|c],dp[j]+a)
#    print(dp)

print(dp[2**N-1] if dp[2**N-1]!=inf else -1)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
keys=[]
for i in range(M):
    a,b=map(int,input().split())
    c=list(map(int,input().split()))
    cans=0
    for i in c:
        cans+=2**(i-1)
    keys.append((a,cans))

#print(keys)

dp=[12*(10**5)+1 for j in range(2**N)]
dp[0]=0

for key in keys:
    for j in range(2**N):
        dp[j|key[1]]=min(dp[j|key[1]],dp[j]+key[0])
#    print(dp)

print(dp[2**N-1] if dp[2**N-1]!=12*(10**5)+1 else -1)

Fixed submission:
N,M=map(int,input().split())
inf=12*(10**5)+1

dp=[inf for j in range(2**N)]
dp[0]=0

for i in range(M):
    a,b=map(int,input().split())
    c=sum([1<<(i-1) for i in list(map(int,input().split()))])
#    print(a,b,c)
    for j in range(2**N):
        dp[j|c]=min(dp[j|c],dp[j]+a)
#    print(dp)

print(dp[2**N-1] if dp[2**N-1]!=inf else -1)

Buggy python submission (verdict: Time Limit Exceeded):
def view():
    global keyboxes
    for keybox in keyboxes:
        for key in keybox:
            print(key.value,key.cans)
        print()

class Key():
    def __init__(self,value,cans):
        self.value=value
        self.cans=cans
    
    def __eq__(self,other):
        return self.value==other.value
    
    def __lt__(self,other):
        return self.value<other.value
    
    def __gt__(self,other):
        return self.value>other.value
    
N,M=map(int,input().split())
keys=[]
for i in range(M):
    a,b=map(int,input().split())
    c=list(map(int,input().split()))
    cans=0
    for i in c:
        cans+=2**(i-1)
    keys.append(Key(a,cans))

dp=[12*(10**5)+1 for j in range(2**N)]
dp[0]=0

for key in keys:
    for j in range(2**N):
        dp[j|key.cans]=min(dp[j|key.cans],dp[j]+key.value)

print(dp[2**N-1] if dp[2**N-1]!=12*(10**5)+1 else -1)

Fixed submission:
N,M=map(int,input().split())
inf=12*(10**5)+1

dp=[inf for j in range(2**N)]
dp[0]=0

for i in range(M):
    a,b=map(int,input().split())
    c=sum([1<<(i-1) for i in list(map(int,input().split()))])
#    print(a,b,c)
    for j in range(2**N):
        dp[j|c]=min(dp[j|c],dp[j]+a)
#    print(dp)

print(dp[2**N-1] if dp[2**N-1]!=inf else -1)