import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N, M = rl()
A = []
Cs = []
for i in range(M):
	a, b = rl()
	C = rl()
	A.append(a)
	Cs.append(C)

def get_bit(C):
	b = 0
	for c in C:
		b = b | (1 << (c-1))
	return b
bits =[]
for C in Cs:
	b = get_bit(C)
	bits.append(b)

start = 0
end = 2**N-1

import heapq

heap = []
heapq.heappush(heap, (0, start))

visited = {}
ans = -1
while heap:
	c, n = heapq.heappop(heap)
	if n == end:
		ans = c
		break
	for i, b in enumerate(bits):
		m = n | b
		nc = c + A[i]
		if m in visited and nc >= visited[m]:
			continue
		visited[m] = nc
		heapq.heappush(heap, (nc, m))
print(ans) import sys, math sys math input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline rs = lambda: input().strip() rs lambda: input().strip() input().strip() ().strip () input strip ri = lambda: int(input()) ri lambda: int(input()) int(input()) int input() input rl = lambda: list(map(int, input().split())) rl lambda: list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split mod = 10**9 + 7 mod 10**9 + 7 10**9 10 9 7 N, M = rl() N rl() rl M A = [] A [] Cs = [] Cs [] for i in range(M):
	a, b = rl()
	C = rl()
	A.append(a)
	Cs.append(C) i range(M) range M a, b = rl() a rl() rl b C = rl() C rl() rl A.append(a) A.append A append a Cs.append(C) Cs.append Cs append C def get_bit(C):
	b = 0
	for c in C:
		b = b | (1 << (c-1))
	return b get_bit b = 0 b 0 for c in C:
		b = b | (1 << (c-1))
	 c C b = b | (1 << (c-1)) b b | (1 << (c-1)) b 1 << (c-1) 1 c-1 c 1 return b b C C bits =[] bits [] for C in Cs:
	b = get_bit(C)
	bits.append(b) C Cs b = get_bit(C) b get_bit(C) get_bit C bits.append(b) bits.append bits append b start = 0 start 0 end = 2**N-1 end 2**N-1 2**N 2 N 1 import heapq heapq heap = [] heap [] heapq.heappush(heap, (0, start)) heapq.heappush heapq heappush heap (0, start) 0 start visited = {} visited {} ans = -1 ans -1 while heap:
	c, n = heapq.heappop(heap)
	if n == end:
		ans = c
		break
	for i, b in enumerate(bits):
		m = n | b
		nc = c + A[i]
		if m in visited and nc >= visited[m]:
			continue
		visited[m] = nc
		heapq.heappush(heap, (nc, m)) heap c, n = heapq.heappop(heap) c heapq.heappop(heap) heapq.heappop heapq heappop heap n if n == end:
		ans = c
		break
	 n == end n end ans = c ans c break for i, b in enumerate(bits):
		m = n | b
		nc = c + A[i]
		if m in visited and nc >= visited[m]:
			continue
		visited[m] = nc
		heapq.heappush(heap, (nc, m)) i b enumerate(bits) enumerate bits m = n | b m n | b n b nc = c + A[i] nc c + A[i] c A[i] A i if m in visited and nc >= visited[m]:
			continue
		 m in visited and nc >= visited[m] m in visited m visited nc >= visited[m] nc visited[m] visited m continue visited[m] = nc visited[m] visited m nc heapq.heappush(heap, (nc, m)) heapq.heappush heapq heappush heap (nc, m) nc m print(ans) print ans N, M = rl() rl() N b = get_bit(C) get_bit(C) b A = [] [] A rl = lambda: list(map(int, input().split())) lambda: list(map(int, input().split())) rl ri = lambda: int(input()) lambda: int(input()) ri M = rl() rl() M ans = c c ans Cs = [] [] Cs C = rl() rl() C nc = c + A[i] c + A[i] nc n = heapq.heappop(heap) heapq.heappop(heap) n def get_bit(C):
	b = 0
	for c in C:
		b = b | (1 << (c-1))
	return b def get_bit(C):
	b = 0
	for c in C:
		b = b | (1 << (c-1))
	return b get_bit ans = -1 -1 ans end = 2**N-1 2**N-1 end rs = lambda: input().strip() lambda: input().strip() rs heap = [] [] heap m = n | b n | b m input = sys.stdin.readline sys.stdin.readline input b = rl() rl() b visited = {} {} visited mod = 10**9 + 7 10**9 + 7 mod c, n = heapq.heappop(heap) heapq.heappop(heap) c bits =[] [] bits a, b = rl() rl() a start = 0 0 start
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N, M = rl()
A = []
Cs = []
for i in range(M):
	a, b = rl()
	C = rl()
	A.append(a)
	Cs.append(C)

def get_bit(C):
	b = 0
	for c in C:
		b = b | (1 << (c-1))
	return b
bits =[]
for C in Cs:
	b = get_bit(C)
	bits.append(b)

start = 0
end = 2**N-1

import heapq

heap = []
heapq.heappush(heap, (0, start))

visited = {}
ans = -1
while heap:
	c, n = heapq.heappop(heap)
	if n == end:
		ans = c
		break
	for i, b in enumerate(bits):
		m = n | b
		nc = c + A[i]
		if m in visited and nc >= visited[m]:
			continue
		visited[m] = nc
		heapq.heappush(heap, (nc, m))
print(ans)
