Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,raw_input().split())
keys = [0]*m
for i in xrange(m):
	a,b = map(int,raw_input().split())
	c = map(int,raw_input().split())
	mask = 0
	for x in c:
		mask += 1<<(x-1)
	keys[i] = (mask,a)

dp = []
M = 1<<n
for i in xrange(m+1):
	dp.append([10**9]*M)
	dp[i][0] = 0
	
for i in xrange(m):
	key = keys[i]
	for j in xrange(M):
		k = j|keys[i][0]
		dp[i+1][k] = min(dp[i+1][k], dp[i][j]+keys[i][1])
		dp[i+1][j] = min(dp[i+1][j], dp[i][j])
 
if dp[m][M-1] >= 10**9:
	print -1
else:
	print dp[m][M-1]

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

M = 1<<n
dp = [10**9]*M
dp[0] = 0
for i in xrange(m):
	a,b = map(int,raw_input().split())
	c = map(int,raw_input().split())
	mask = 0
	for x in c:
		mask += 1<<(x-1)
	for j in xrange(M):
		dp[j|mask] = min(dp[j|mask], dp[j]+a)
	#print dp
 
if dp[M-1] >= 10**9:
	print -1
else:
	print dp[M-1]

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,raw_input().split())
keys = []
for i in xrange(m):
	a,b = map(int,raw_input().split())
	c = map(int,raw_input().split())
	mask = 0
	for x in c:
		mask += 1<<(x-1)
	keys.append((mask,a))

dp = []
M = 1<<n
for i in xrange(m+1):
	dp.append([10**9]*M)
	dp[i][0] = 0
	
for i in xrange(m):
	key = keys[i]
	for j in xrange(M):
		k = j|keys[i][0]
		dp[i+1][k] = min(dp[i+1][k], dp[i][j]+keys[i][1])
		dp[i+1][j] = min(dp[i+1][j], dp[i][j])
 
if dp[m][M-1] >= 10**9:
	print -1
else:
	print dp[m][M-1]

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

M = 1<<n
dp = [10**9]*M
dp[0] = 0
for i in xrange(m):
	a,b = map(int,raw_input().split())
	c = map(int,raw_input().split())
	mask = 0
	for x in c:
		mask += 1<<(x-1)
	for j in xrange(M):
		dp[j|mask] = min(dp[j|mask], dp[j]+a)
	#print dp
 
if dp[M-1] >= 10**9:
	print -1
else:
	print dp[M-1]

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,raw_input().split())
keys = []
for i in xrange(m):
	a,b = map(int,raw_input().split())
	c = map(int,raw_input().split())
	mask = 0
	for x in c:
		mask += 2**(x-1)
	keys.append((mask,a))
#print(keys)
dp = []
M = 2**n
for i in xrange(m+1):
	dp.append([10**9]*M)
	dp[i][0] = 0
	
for i in xrange(m):
	key = keys[i]
	for j in xrange(M):
		dp[i+1][j|key[0]] = min(dp[i+1][j|key[0]], dp[i][j]+key[1])
		dp[i+1][j] = min(dp[i+1][j], dp[i][j])

if dp[m][M-1] >= 10**9:
	print -1
else:
	print dp[m][M-1]

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

M = 1<<n
dp = [10**9]*M
dp[0] = 0
for i in xrange(m):
	a,b = map(int,raw_input().split())
	c = map(int,raw_input().split())
	mask = 0
	for x in c:
		mask += 1<<(x-1)
	for j in xrange(M):
		dp[j|mask] = min(dp[j|mask], dp[j]+a)
	#print dp
 
if dp[M-1] >= 10**9:
	print -1
else:
	print dp[M-1]

Buggy python submission (verdict: Time Limit Exceeded):
#python 3
n,m = map(int,input().split())
keys = []
for i in range(m):
	a,b = map(int,input().split())
	c = map(int,input().split())
	mask = 0
	for x in c:
		mask += 2**(x-1)
	keys.append((mask,a))
#print(keys)
dp = []
M = 2**n
for i in range(m+1):
	dp.append([10**10]*(M))

for i in range(m+1):
	dp[i][0] = 0
	
for i in range(m):
	key = keys[i]
	for j in range(M):
		dp[i+1][j|key[0]] = min(dp[i+1][j|key[0]], dp[i][j]+key[1])
		dp[i+1][j] = min(dp[i+1][j], dp[i][j])

if dp[m][M-1] > 10**9:
	print(-1)
else:
	print(dp[m][M-1])

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

M = 1<<n
dp = [10**9]*M
dp[0] = 0
for i in xrange(m):
	a,b = map(int,raw_input().split())
	c = map(int,raw_input().split())
	mask = 0
	for x in c:
		mask += 1<<(x-1)
	for j in xrange(M):
		dp[j|mask] = min(dp[j|mask], dp[j]+a)
	#print dp
 
if dp[M-1] >= 10**9:
	print -1
else:
	print dp[M-1]