Buggy python submission (verdict: Runtime Error):
def main():
    n, m = map(int, input().split())
	all_patterns = 2**n
    DP = [10**9] * all_patterns
    DP[0] = 0
    for _ in range(m):
        cost, types = map(int, input().split())
        to_open = list(map(int, input().split()))

        openable = 0
        for open in to_open:
            openable += 1 << (open-1)

        for opened in range(all_patterns):
            pattern = opened | openable
            new_cost = DP[opened] + cost
            if DP[pattern] > new_cost:
                DP[pattern] = new_cost

    full_open = 2**n - 1
    ans = DP[full_open]

    if ans == 10 ** 9:
        ans = -1

    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
n, m = map(int, input().split())

keys = []

for i in range(m):
    cost, num = map(int, input().split())
    C = list(map(int, input().split()))
    can_open = 0
    for c in C:
        can_open += 2 ** (c-1)
    keys.append([cost, can_open])

DP = {}
for i in range(2**n):
    DP[i] = float('INF')
DP[0] = 0

for cost, can_open in keys:
    for key in DP.keys():
        pre_cost = DP[key]
        next_key = key | can_open
        DP[next_key] = min(DP[next_key], pre_cost+cost)


full_open = (1 << n) - 1

if DP[full_open] == float('INF'):
    print(-1)
else:
    print(DP[full_open])

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

keys = []

for i in range(m):
    cost, num = map(int, input().split())
    C = list(map(int, input().split()))
    can_open = 0
    for c in C:
        can_open += 2 ** (c-1)
    keys.append([cost, can_open])

DP = {}
for i in range(2**n):
    DP[i] = float('INF')
DP[0] = 0

for cost, can_open in keys:
    for key in DP.keys():
        pre_cost = DP[key]
        next_key = key | can_open
        DP[next_key] = min(DP[next_key], pre_cost+cost)


full_open = (1 << n) - 1

if DP[full_open] == float('INF'):
    print(-1)
else:
    print(DP[full_open])

Fixed submission:
n, m = map(int, input().split())

keys = []

for i in range(m):
    cost, num = map(int, input().split())
    C = list(map(int, input().split()))
    can_open = 0
    for c in C:
        can_open += 2 ** (c-1)
    keys.append([cost, can_open])

DP = {}
for i in range(2**n):
    DP[i] = float('INF')
DP[0] = 0

for cost, can_open in keys:
    for key in DP.keys():
        pre_cost = DP[key]
        next_key = key | can_open
        DP[next_key] = min(DP[next_key], pre_cost+cost)


full_open = (1 << n) - 1

if DP[full_open] == float('INF'):
    print(-1)
else:
    print(DP[full_open])

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

keys = []

for i in range(m):
    cost, num = map(int, input().split())
    C = list(map(int, input().split()))
    can_open = 0
    for c in C:
        can_open += 2 ** (c-1)
    keys.append([cost, can_open])

DP = {}
for i in range(2**n):
    DP[i] = float('INF')
DP[0] = 0

for cost, can_open in keys:
    for key in DP.keys():
        pre_cost = DP[key]
        next_key = key | can_open
        if next_key in DP.keys():
            DP[next_key] = min(DP[next_key], pre_cost+cost)
        else:
            DP[next_key] = pre_cost + cost

full_open = (1 << n) - 1

if DP[full_open] == float('INF'):
    print(-1)
else:
    print(DP[full_open])


Fixed submission:
n, m = map(int, input().split())

keys = []

for i in range(m):
    cost, num = map(int, input().split())
    C = list(map(int, input().split()))
    can_open = 0
    for c in C:
        can_open += 2 ** (c-1)
    keys.append([cost, can_open])

DP = {}
for i in range(2**n):
    DP[i] = float('INF')
DP[0] = 0

for cost, can_open in keys:
    for key in DP.keys():
        pre_cost = DP[key]
        next_key = key | can_open
        DP[next_key] = min(DP[next_key], pre_cost+cost)


full_open = (1 << n) - 1

if DP[full_open] == float('INF'):
    print(-1)
else:
    print(DP[full_open])