n, m = map(int, input().split())

dp = [[10**10 for _ in range(2**n)] for j in range(m)]
dp[0][0] = 0
a, b = map(int, input().split())
c = list(map(int, input().split()))
idx = 0
for cc in c:
  idx += 2**(cc-1)
for j in range(1, 2**n):
  if ~idx & j == 0:
    dp[0][j] = a

for i in range(1, m):
  a, b = map(int, input().split())
  c = list(map(int, input().split()))
  idx = 0
  for cc in c:
    idx += 2**(cc-1)
  for j in range(2**n):
    dp[i][j] = min(dp[i-1][j], dp[i-1][(j|idx)^idx]+a)

if dp[-1][-1] != 10**10:
  print(dp[-1][-1])
else:
  print(-1) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m [10**10 for _ in range(2**n)] for j in range(m) for j in range(m) j range(m) range m for j in range(m) [10**10 for _ in range(2**n)] dp = [[10**10 for _ in range(2**n)] for j in range(m)] dp [[10**10 for _ in range(2**n)] for j in range(m)] dp[0][0] = 0 dp[0][0] [0] dp 0 0 0 a, b = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b c = list(map(int, input().split())) c list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split idx = 0 idx 0 for cc in c:
  idx += 2**(cc-1) cc c idx += 2**(cc-1) idx 2**(cc-1) 2 cc-1 cc 1 for j in range(1, 2**n):
  if ~idx & j == 0:
    dp[0][j] = a j range(1, 2**n) range 1 2**n 2 n if ~idx & j == 0:
    dp[0][j] = a ~idx & j == 0 ~idx & j ~idx idx j 0 dp[0][j] = a dp[0][j] [0] dp 0 j a for i in range(1, m):
  a, b = map(int, input().split())
  c = list(map(int, input().split()))
  idx = 0
  for cc in c:
    idx += 2**(cc-1)
  for j in range(2**n):
    dp[i][j] = min(dp[i-1][j], dp[i-1][(j|idx)^idx]+a) i range(1, m) range 1 m a, b = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b c = list(map(int, input().split())) c list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split idx = 0 idx 0 for cc in c:
    idx += 2**(cc-1)
   cc c idx += 2**(cc-1) idx 2**(cc-1) 2 cc-1 cc 1 for j in range(2**n):
    dp[i][j] = min(dp[i-1][j], dp[i-1][(j|idx)^idx]+a) j range(2**n) range 2**n 2 n dp[i][j] = min(dp[i-1][j], dp[i-1][(j|idx)^idx]+a) dp[i][j] [i] dp i j min(dp[i-1][j], dp[i-1][(j|idx)^idx]+a) min dp[i-1][j] [i-1] dp i-1 i 1 j dp[i-1][(j|idx)^idx]+a dp[i-1][(j|idx)^idx] [i-1] dp i-1 i 1 (j|idx)^idx j|idx j idx idx a if dp[-1][-1] != 10**10:
  print(dp[-1][-1])
else:
  print(-1) dp[-1][-1] != 10**10 dp[-1][-1] [-1] dp -1 -1 10**10 10 10 print(dp[-1][-1]) print dp[-1][-1] [-1] dp -1 -1 print(-1) print -1 b = map(int, input().split()) map(int, input().split()) b idx = 0 0 idx m = map(int, input().split()) map(int, input().split()) m c = list(map(int, input().split())) list(map(int, input().split())) c n, m = map(int, input().split()) map(int, input().split()) n idx += 2**(cc-1) 2**(cc-1) idx c = list(map(int, input().split())) list(map(int, input().split())) c a, b = map(int, input().split()) map(int, input().split()) a a, b = map(int, input().split()) map(int, input().split()) a b = map(int, input().split()) map(int, input().split()) b dp = [[10**10 for _ in range(2**n)] for j in range(m)] [[10**10 for _ in range(2**n)] for j in range(m)] dp idx += 2**(cc-1) 2**(cc-1) idx idx = 0 0 idx
n, m = map(int, input().split())

dp = [[10**10 for _ in range(2**n)] for j in range(m)]
dp[0][0] = 0
a, b = map(int, input().split())
c = list(map(int, input().split()))
idx = 0
for cc in c:
  idx += 2**(cc-1)
for j in range(1, 2**n):
  if ~idx & j == 0:
    dp[0][j] = a

for i in range(1, m):
  a, b = map(int, input().split())
  c = list(map(int, input().split()))
  idx = 0
  for cc in c:
    idx += 2**(cc-1)
  for j in range(2**n):
    dp[i][j] = min(dp[i-1][j], dp[i-1][(j|idx)^idx]+a)

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