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

f=[10**7 for x in range(2**n)]
l=[]

for i in range(m):
  a,b = map(int,input().split())
  c = [int(x) for x in input().split()]
  s = 0
  for j in c:
    s += 2**(j-1)
  f[s]=min(f[s],a)

for i in range(2**n):
  if f[i] != 10**7:
    l.append([i,f[i]])

v=[[10**7 for x in range(2**n)] for y in range(2)]
v[0][0]=0

i=0
for s,a in l:
  for j in range(2**n):
    v[(i+1)%2][j] = v[i%2][j]
  for j in range(2**n):
    if v[i%2][j] != 10**7:
      v[(i+1)%2][j|s] = min(v[(i+1)%2][j|s], v[i%2][j]+a)
  i+=1

print(v[i%2][2**n-1] if v[i%2][2**n-1] != 10**7 else -1)


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

f=[10**7 for x in range(2**n)]
for i in range(m):
  a,b = map(int,input().split())
  c = [int(x) for x in input().split()]
  s = 0
  for j in c:
    s += 2**(j-1)
  f[s]=min(f[s],a)

l=[]
for i in range(2**n):
  if f[i] != 10**7:
    l.append([i,f[i]])

v=[10**7 for x in range(2**n)]
v[0]=0

for s,a in l:
  for j in range(2**n):
    if v[j] != 10**7:
      v[j|s] = min(v[j|s], v[j]+a)

print(v[2**n-1] if v[2**n-1] != 10**7 else -1)

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

l=[]

for i in range(m):
  a,b = map(int,input().split())
  c = [int(x) for x in input().split()]
  s = 0
  for j in c:
    s += 2**(j-1)
  l.append([s,a])

#print(l)

v=[[10**7 for x in range(2**n)] for y in range(2)]
v[0][0]=0

i=0
for s,a in l:
  for j in range(2**n):
    v[(i+1)%2][j] = v[i%2][j]
  for j in range(2**n):
    if v[i%2][j] != 10**7:
      v[(i+1)%2][j|s] = min(v[(i+1)%2][j|s], v[i%2][j]+a)
  i+=1

print(v[(i+1)%2][2**n-1] if v[(i+1)%2][2**n-1] != 10**7 else -1)


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

f=[10**7 for x in range(2**n)]
for i in range(m):
  a,b = map(int,input().split())
  c = [int(x) for x in input().split()]
  s = 0
  for j in c:
    s += 2**(j-1)
  f[s]=min(f[s],a)

l=[]
for i in range(2**n):
  if f[i] != 10**7:
    l.append([i,f[i]])

v=[10**7 for x in range(2**n)]
v[0]=0

for s,a in l:
  for j in range(2**n):
    if v[j] != 10**7:
      v[j|s] = min(v[j|s], v[j]+a)

print(v[2**n-1] if v[2**n-1] != 10**7 else -1)

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

l=[[] for x in range(n)]
v=[[10**7 for x in range(2**n)] for y in range(2)]
v[0][0]=0

#print(v)
for i in range(m):
  a,b = map(int,input().split())
  c = [int(x) for x in input().split()]
  s = 0
  for j in c:
    s += 2**(j-1)
  for j in c:
    l[j-1].append([a,s])

for i in range(n):
  for j in range(2**n):
    v[(i+1)%2][j] = v[i%2][j]
  for j in range(2**n):
    for k in l[i]:
      if v[i%2][j] != 10**7:
          v[(i+1)%2][j|k[1]] = min(v[(i+1)%2][j|k[1]], v[i%2][j]+k[0])

print(v[(i+1)%2][2**n-1] if v[(i+1)%2][2**n-1] != 10**7 else -1)


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

f=[10**7 for x in range(2**n)]
for i in range(m):
  a,b = map(int,input().split())
  c = [int(x) for x in input().split()]
  s = 0
  for j in c:
    s += 2**(j-1)
  f[s]=min(f[s],a)

l=[]
for i in range(2**n):
  if f[i] != 10**7:
    l.append([i,f[i]])

v=[10**7 for x in range(2**n)]
v[0]=0

for s,a in l:
  for j in range(2**n):
    if v[j] != 10**7:
      v[j|s] = min(v[j|s], v[j]+a)

print(v[2**n-1] if v[2**n-1] != 10**7 else -1)