Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(lambda x:int(x), input().split()))
 
key_list = {}
 
for i in range(m):
    key_price, _ = list(map(lambda x:int(x), input().split()))
    open_list = list(map(lambda x:int(x), input().split()))
    key_list[i] = [key_price, open_list]
    
situation_val = 1 << n
 
dp = [[float('INF')] * situation_val for i in range(m+1)]
for i in range(m+1):
    dp[i][0] = 0
 
for i in range(m):
    price = key_list[i][0]
    treasure = key_list[i][1]
    key_val = 0
    for v in treasure:
        key_val += (1 << v-1)
        
    for j in range(situation_val):
        key_used_situation = j | key_val
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])
        dp[i+1][key_used_situation] = min(dp[i+1][key_used_situation], dp[i][j]+price)
        
        
ans = dp[m][situation_val-1]

if ans == float('inf'):
    print(-1)
else:
    print(ans)

Fixed submission:
n, m = list(map(lambda x:int(x), input().split()))
 
key_list = {}
 
for i in range(m):
    key_price, _ = list(map(lambda x:int(x), input().split()))
    open_list = list(map(lambda x:int(x), input().split()))
    key_list[i] = [key_price, open_list]
    
situation_val = 1 << n
 
dp = [[float('INF')] * situation_val for i in range(m+1)]
for i in range(m+1):
    dp[i][0] = 0
 
for i in range(m):
    price = key_list[i][0]
    treasure = key_list[i][1]
    key_val = 0
    for v in treasure:
        key_val += (1 << v-1)
        
    for j in range(situation_val):
        key_used_situation = j | key_val
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])
        dp[i+1][key_used_situation] = min(dp[i+1][key_used_situation], dp[i][j]+price)
        
        
ans = dp[m][situation_val-1]

if ans == float('inf'):
    print(-1)
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

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

key_list = {}

for i in range(m):
    key_price, _ = list(map(lambda x:int(x), input().split()))
    open_list = list(map(lambda x:int(x), input().split()))
    key_list[i] = [key_price, open_list]
    
situation_val = 1 << n

dp = [[float('INF')] * situation_val for i in range(m+1)]
dp[0][0] = 0

for i in range(m):
    price = key_list[i][0]
    treasure = key_list[i][1]
    key_val = 0
    for v in treasure:
        key_val += (1 << v-1)
        
    for j in range(situation_val):
        key_used_situation = j | key_val
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])
        dp[i+1][key_used_situation] = min(dp[i][key_used_situation], dp[i+1][key_used_situation], dp[i][j]+price)
        
        
ans = dp[m][situation_val-1]

if ans == float('inf'):
    print(-1)
else:
    print(ans)


Fixed submission:
n, m = list(map(lambda x:int(x), input().split()))
 
key_list = {}
 
for i in range(m):
    key_price, _ = list(map(lambda x:int(x), input().split()))
    open_list = list(map(lambda x:int(x), input().split()))
    key_list[i] = [key_price, open_list]
    
situation_val = 1 << n
 
dp = [[float('INF')] * situation_val for i in range(m+1)]
for i in range(m+1):
    dp[i][0] = 0
 
for i in range(m):
    price = key_list[i][0]
    treasure = key_list[i][1]
    key_val = 0
    for v in treasure:
        key_val += (1 << v-1)
        
    for j in range(situation_val):
        key_used_situation = j | key_val
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])
        dp[i+1][key_used_situation] = min(dp[i+1][key_used_situation], dp[i][j]+price)
        
        
ans = dp[m][situation_val-1]

if ans == float('inf'):
    print(-1)
else:
    print(ans)