Buggy python submission (verdict: Time Limit Exceeded):
n, m = [int(i) for i in input().split()]
dp_1 = [float("inf")] * (2**n)
dp_2 = [float("inf")] * (2**n)
dp_1[0] = 0

for i in range(m):
    a, _ = [int(_) for _ in input().split()]
    c = sum([2**(int(_)-1) for _ in input().split()])

    for j in range(2**n):
        if i % 2 == 0:
            dp_2[j|c] = min(dp_1[j|c], dp_1[j] + a, dp_2[j|c])
            dp_2[j] = min(dp_1[j], dp_2[j])
        else:
            dp_1[j|c] = min(dp_2[j|c], dp_2[j] + a, dp_1[j|c])
            dp_1[j] = min(dp_2[j], dp_1[j])

print([dp_1[-1], -1][dp_1[-1] == float("inf")])

Fixed submission:
n, m = [int(i) for i in input().split()]
dp = [[float("inf") for i in range(2**n)] for j in range(m+1)]
dp[0][0] = 0

for i in range(m):
    a, _ = [int(_) for _ in input().split()]
    c = sum([2**(int(_)-1) for _ in input().split()])

    for j in range(2**n):
        dp[i+1][j|c] = min(dp[i][j|c], dp[i][j] + a, dp[i+1][j|c])
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])

print([dp[-1][-1], -1][dp[-1][-1] == float("inf")])

Buggy python submission (verdict: Time Limit Exceeded):
n, m = [int(i) for i in input().split()]
dp_1 = [float("inf") for i in range(2**n)]
dp_2 = [float("inf") for i in range(2**n)]
dp_1[0] = 0

for i in range(m):
    a, _ = [int(_) for _ in input().split()]
    c = sum([2**(int(_)-1) for _ in input().split()])

    for j in range(2**n):
        if i % 2 == 0:
            dp_2[j|c] = min(dp_1[j|c], dp_1[j] + a, dp_2[j|c])
            dp_2[j] = min(dp_1[j], dp_2[j])
        else:
            dp_1[j|c] = min(dp_2[j|c], dp_2[j] + a, dp_1[j|c])
            dp_1[j] = min(dp_2[j], dp_1[j])

print([dp_1[-1], -1][dp_1[-1] == float("inf")])


Fixed submission:
n, m = [int(i) for i in input().split()]
dp = [[float("inf") for i in range(2**n)] for j in range(m+1)]
dp[0][0] = 0

for i in range(m):
    a, _ = [int(_) for _ in input().split()]
    c = sum([2**(int(_)-1) for _ in input().split()])

    for j in range(2**n):
        dp[i+1][j|c] = min(dp[i][j|c], dp[i][j] + a, dp[i+1][j|c])
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])

print([dp[-1][-1], -1][dp[-1][-1] == float("inf")])

Buggy python submission (verdict: Time Limit Exceeded):
n, m = [int(i) for i in input().split()]
dp_prev = [float("inf") for i in range(2**n)]
dp_next = [float("inf") for i in range(2**n)]
dp_prev[0] = 0
s = {0}

for i in range(m):
    a, _ = [int(_) for _ in input().split()]
    c = sum([2**(int(_)-1) for _ in input().split()])

    s_next = set()

    for j in s:
        dp_next[j|c] = min(dp_prev[j|c], dp_prev[j] + a, dp_next[j|c])
        dp_next[j] = min(dp_prev[j], dp_next[j])
        s_next.add(j|c)

    dp_prev = dp_next[:]
    s |= s_next

print([dp_next[-1], -1][dp_next[-1] == float("inf")])


Fixed submission:
n, m = [int(i) for i in input().split()]
dp = [[float("inf") for i in range(2**n)] for j in range(m+1)]
dp[0][0] = 0

for i in range(m):
    a, _ = [int(_) for _ in input().split()]
    c = sum([2**(int(_)-1) for _ in input().split()])

    for j in range(2**n):
        dp[i+1][j|c] = min(dp[i][j|c], dp[i][j] + a, dp[i+1][j|c])
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])

print([dp[-1][-1], -1][dp[-1][-1] == float("inf")])

Buggy python submission (verdict: Time Limit Exceeded):
n, m = [int(i) for i in input().split()]
dp_prev = [float("inf") for i in range(2**n)]
dp_next = [float("inf") for i in range(2**n)]
dp_prev[0] = 0

for i in range(m):
    a, _ = [int(_) for _ in input().split()]
    c = sum([2**(int(_)-1) for _ in input().split()])

    for j in range(2**n):
        dp_next[j|c] = min(dp_prev[j|c], dp_prev[j] + a, dp_next[j|c])
        dp_next[j] = min(dp_prev[j], dp_next[j])
    dp_prev = dp_next[:]


print([dp_next[-1], -1][dp_next[-1] == float("inf")])


Fixed submission:
n, m = [int(i) for i in input().split()]
dp = [[float("inf") for i in range(2**n)] for j in range(m+1)]
dp[0][0] = 0

for i in range(m):
    a, _ = [int(_) for _ in input().split()]
    c = sum([2**(int(_)-1) for _ in input().split()])

    for j in range(2**n):
        dp[i+1][j|c] = min(dp[i][j|c], dp[i][j] + a, dp[i+1][j|c])
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])

print([dp[-1][-1], -1][dp[-1][-1] == float("inf")])

Buggy python submission (verdict: Time Limit Exceeded):
n, m = [int(i) for i in input().split()]
dp = [[float("inf") for i in range(2**n)] for j in range(m+1)]
dp[0][0] = 0

for i in range(m):
    a, _ = [int(_) for _ in input().split()]
    c = sum([2**(int(_)-1) for _ in input().split()])

    for j in range(2**n):
        dp[i+1][j|c] = min(dp[i][j|c], dp[i][j] + a, dp[i+1][j|c])
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])

print([dp[-1][-1], -1][dp[-1][-1] == float("inf")])

Fixed submission:
n, m = [int(i) for i in input().split()]
dp = [[float("inf") for i in range(2**n)] for j in range(m+1)]
dp[0][0] = 0

for i in range(m):
    a, _ = [int(_) for _ in input().split()]
    c = sum([2**(int(_)-1) for _ in input().split()])

    for j in range(2**n):
        dp[i+1][j|c] = min(dp[i][j|c], dp[i][j] + a, dp[i+1][j|c])
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])

print([dp[-1][-1], -1][dp[-1][-1] == float("inf")])

Buggy python submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
dp = [float("inf") for i in range(n**2)]

for i in range(m):
    a, _ = [int(i) for i in input().split()]
    c = sum([2**(int(i)-1) for i in input().split()])
    for j in range(n**2):
        if j == 0:
            dp[c] = min(dp[c], a)

        elif dp[j] != float("inf"):
            dp[j|c] = min(dp[j|c], dp[j] + a)

print([dp[-1], -1][dp[-1] == float("inf")])

Fixed submission:
n, m = [int(i) for i in input().split()]
dp = [[float("inf") for i in range(2**n)] for j in range(m+1)]
dp[0][0] = 0

for i in range(m):
    a, _ = [int(_) for _ in input().split()]
    c = sum([2**(int(_)-1) for _ in input().split()])

    for j in range(2**n):
        dp[i+1][j|c] = min(dp[i][j|c], dp[i][j] + a, dp[i+1][j|c])
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])

print([dp[-1][-1], -1][dp[-1][-1] == float("inf")])