Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [0 for i in range(m)]
b = [0 for i in range(m)]
c = []
for i in range(m):
    a[i], b[i] = map(int, input().split())
    c.append(list(map(int, input().split())))

dp = [10**6 for i in range(2**n)]
dp[0] = 0

string = [0 for i in range(n)]
for i in c[0]:
    string[i-1] = 1
string = ''.join(map(str, string))
num = int(string, 2)
dp[num] = a[0]

for i in range(1, m):
    string = [0 for i in range(n)]
    for j in c[i]:
        string[j-1] = 1
    string = ''.join(map(str, string))
    di = int(string, 2)
    for j in range(2**n):
        dp[j|di] = min(dp[j|di], dp[j]+a[i])

if dp[2**n-1] != 10**6:
    print(dp[2**n-1])
else:
    print(-1)

Fixed submission:
n, m = map(int, input().split())
a = [0 for i in range(m)]
b = [0 for i in range(m)]
c = []
for i in range(m):
    a[i], b[i] = map(int, input().split())
    c.append(list(map(int, input().split())))

dp = [10**6 for i in range(2**n)]
dp[0] = 0

string = [0 for i in range(n)]
for i in c[0]:
    string[i-1] = 1
string = ''.join(map(str, string))
num = int(string, 2)
dp[num] = a[0]

for i in range(1, m):
    string = [0 for i in range(n)]
    for j in c[i]:
        string[j-1] = 1
    string = ''.join(map(str, string))
    di = int(string, 2)
    for j in range(2**n):
        dp[j|di] = min(dp[j|di], dp[j]+a[i])

if dp[2**n-1] != 10**6:
    print(dp[2**n-1])
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n, m = map(int, input().split())
a = [0 for i in range(m)]
b = [0 for i in range(m)]
c = []
for i in range(m):
    a[i], b[i] = map(int, input().split())
    c.append(list(map(int, input().split())))

dp = [np.inf for i in range(2**n)]
dp[0] = 0

string = [0 for i in range(n)]
for i in c[0]:
    string[i-1] = 1
string = ''.join(map(str, string))
num = int(string, 2)
dp[num] = a[0]

for i in range(1, m):
    string = [0 for i in range(n)]
    for j in c[i]:
        string[j-1] = 1
    string = ''.join(map(str, string))
    di = int(string, 2)
    for j in range(2**n):
        dp[j|di] = min(dp[j|di], dp[j]+a[i])

if dp[2**n-1] != np.inf:
    print(dp[2**n-1])
else:
    print(-1)

Fixed submission:
n, m = map(int, input().split())
a = [0 for i in range(m)]
b = [0 for i in range(m)]
c = []
for i in range(m):
    a[i], b[i] = map(int, input().split())
    c.append(list(map(int, input().split())))

dp = [10**6 for i in range(2**n)]
dp[0] = 0

string = [0 for i in range(n)]
for i in c[0]:
    string[i-1] = 1
string = ''.join(map(str, string))
num = int(string, 2)
dp[num] = a[0]

for i in range(1, m):
    string = [0 for i in range(n)]
    for j in c[i]:
        string[j-1] = 1
    string = ''.join(map(str, string))
    di = int(string, 2)
    for j in range(2**n):
        dp[j|di] = min(dp[j|di], dp[j]+a[i])

if dp[2**n-1] != 10**6:
    print(dp[2**n-1])
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n, m = map(int, input().split())
a = [0 for i in range(m)]
b = [0 for i in range(m)]
c = []
for i in range(m):
    a[i], b[i] = map(int, input().split())
    c.append(list(map(int, input().split())))

dp = [[np.inf for i in range(2**n)] for j in range(m)]
for i in range(m):
    dp[i][0] = 0

string = [0 for i in range(n)]
for i in c[0]:
    string[i-1] = 1
string = ''.join(map(str, string))
num = int(string, 2)
dp[0][num] = a[0]

for i in range(1, m):
    string = [0 for i in range(n)]
    for j in c[i]:
        string[j-1] = 1
    string = ''.join(map(str, string))
    di = int(string, 2)
    for j in range(2**n):
        dp[i][j|di] = min(dp[i][j|di], dp[i-1][j|di], dp[i-1][j]+a[i])
    for j in range(2**n):
        if dp[i][j] == np.inf and dp[i-1][j] != np.inf:
            dp[i][j] = dp[i-1][j]

if dp[m-1][2**n-1] != np.inf:
    print(dp[m-1][2**n-1])
else:
    print(-1)

Fixed submission:
n, m = map(int, input().split())
a = [0 for i in range(m)]
b = [0 for i in range(m)]
c = []
for i in range(m):
    a[i], b[i] = map(int, input().split())
    c.append(list(map(int, input().split())))

dp = [10**6 for i in range(2**n)]
dp[0] = 0

string = [0 for i in range(n)]
for i in c[0]:
    string[i-1] = 1
string = ''.join(map(str, string))
num = int(string, 2)
dp[num] = a[0]

for i in range(1, m):
    string = [0 for i in range(n)]
    for j in c[i]:
        string[j-1] = 1
    string = ''.join(map(str, string))
    di = int(string, 2)
    for j in range(2**n):
        dp[j|di] = min(dp[j|di], dp[j]+a[i])

if dp[2**n-1] != 10**6:
    print(dp[2**n-1])
else:
    print(-1)