Buggy python submission (verdict: Runtime Error):
import sys
import heapq
sys.setrecursionlimit(10000000)

def knap(i, used, cost, N, M, Key, K_cost):
    if i == N - 1:
        take = used | Key[i]
        take_cost = cost + K_cost[i]
        a = set([int(i) for i in range(N)])
        if  used == a: return cost
        elif take == a: return take_cost
        else: return -1
    else:
        take = used | Key[i]
        take_cost = knap(i+1, take, cost + K_cost[i], N, M, Key, K_cost)
        not_take_cost = knap(i+1, used, cost, N, M, Key, K_cost)
        if take_cost == not_take_cost == -1: return -1
        elif take_cost == -1: return not_take_cost
        elif not_take_cost == -1: return take_cost
        else: return min(take_cost, not_take_cost)
        

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    Key = dict()
    K_cost = dict()
    for i in range(M):
        a, b = map(int, input().split())
        K_cost[i] = a
        Key[i] = set([int(c) - 1 for c in input().split()])

    print(knap(0, set(), 0, N, M, Key, K_cost))
    return 0

if __name__ == "__main__":
    solve()

Fixed submission:
import sys
import heapq

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    cost = dict()
    for i in range(2 ** N): cost[i] = -1
    cost[0] = 0
    for i in range(M):
        a, b = map(int, input().split())
        c = [int(c) for c in input().split()]
        bit = 0
        for j in c: bit += 2 ** (j - 1)
        for i in range(2 ** N):
            if cost[i] > -1:
                if cost[i | bit] > -1:
                    cost[i | bit] = min(cost[i | bit], cost[i] + a)
                else: cost[i | bit] = cost[i] + a

    #print(cost)

    print(cost[2 ** N - 1])
    return 0

if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Runtime Error):
import sys
import heapq

def knap(i, used, cost, N, M, Key, K_cost):
    if i == N - 1:
        take = used | Key[i]
        take_cost = cost + K_cost[i]
        a = set([int(i) for i in range(N)])
        if  used == a: return cost
        elif take == a: return take_cost
        else: return -1
    else:
        take = used | Key[i]
        take_cost = knap(i+1, take, cost + K_cost[i], N, M, Key, K_cost)
        not_take_cost = knap(i+1, used, cost, N, M, Key, K_cost)
        if take_cost == not_take_cost == -1: return -1
        elif take_cost == -1: return not_take_cost
        elif not_take_cost == -1: return take_cost
        else: return min(take_cost, not_take_cost)
        

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    Key = dict()
    K_cost = dict()
    for i in range(M):
        a, b = map(int, input().split())
        K_cost[i] = a
        Key[i] = set([int(c) - 1 for c in input().split()])

    print(knap(0, set(), 0, N, M, Key, K_cost))
    return 0

if __name__ == "__main__":
    solve()

Fixed submission:
import sys
import heapq

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    cost = dict()
    for i in range(2 ** N): cost[i] = -1
    cost[0] = 0
    for i in range(M):
        a, b = map(int, input().split())
        c = [int(c) for c in input().split()]
        bit = 0
        for j in c: bit += 2 ** (j - 1)
        for i in range(2 ** N):
            if cost[i] > -1:
                if cost[i | bit] > -1:
                    cost[i | bit] = min(cost[i | bit], cost[i] + a)
                else: cost[i | bit] = cost[i] + a

    #print(cost)

    print(cost[2 ** N - 1])
    return 0

if __name__ == "__main__":
    solve()