Buggy python submission (verdict: Time Limit Exceeded):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()
dp = [INF]*(1<<N)
dp[0] = 0

for _ in range(M):
	a, b = MAP()
	c = LIST()
	d = 0
	for x in c:
		d += 1<<(x-1)

	for j in range(1<<N):
		tmp = j|d
		dp[tmp] = min(dp[tmp], dp[j]+a)

if dp[-1] == INF:
	print(-1)
else:
	print(dp[-1])


Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()
dp = [INF]*(1<<N)
dp[0] = 0

for _ in range(M):
	a, b = MAP()
	c = LIST()
	d = 0
	for x in c:
		d += 1<<(x-1)

	for j in range(1<<N):
		tmp = j|d
		dp[tmp] = min(dp[tmp], dp[j]+a)

if dp[-1] == INF:
	print(-1)
else:
	print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()
a = [0] * M
b = [0] * M
d = [0] * M

for i in range(M):
	a[i], b[i] = MAP()
	c = LIST()
	for x in c:
		d[i] += 1<<(x-1)

dp = [INF]*(1<<N)
dp[0] = 0
for i in range(1, M+1):
	for j in range(1<<N):
		dp[j|d[i-1]] = min(dp[j|d[i-1]], dp[j]+a[i-1])

if dp[-1] == INF:
	print(-1)
else:
	print(dp[-1])


Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()
dp = [INF]*(1<<N)
dp[0] = 0

for _ in range(M):
	a, b = MAP()
	c = LIST()
	d = 0
	for x in c:
		d += 1<<(x-1)

	for j in range(1<<N):
		tmp = j|d
		dp[tmp] = min(dp[tmp], dp[j]+a)

if dp[-1] == INF:
	print(-1)
else:
	print(dp[-1])