n,m = map(int, input().split())
ab = []
c = []
for i in range(m):
  ab.append(list(map(int, input().split())))
  c.append(list(map(int, input().split())))
dp = [[10**18] * (2 ** n) for i in range(m+1)]
dp[0][0] = 0
for i,((a,b),c) in enumerate(zip(ab,c)):
  d = 0
  for x in c:
    d += 2 ** (x-1)
  for j in range(2**n):
    NEXT = j | d
    dp[i+1][j] = min(dp[i+1][j], dp[i][j])
    dp[i+1][NEXT] = min(dp[i+1][NEXT], dp[i][j]+a)
ans = dp[m][2**n-1]
if ans == 10 ** 18:
  print(-1)
else:
  print(ans) n,m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m ab = [] ab [] c = [] c [] for i in range(m):
  ab.append(list(map(int, input().split())))
  c.append(list(map(int, input().split()))) i range(m) range m ab.append(list(map(int, input().split()))) ab.append ab append list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split c.append(list(map(int, input().split()))) c.append c append list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split [10**18] * (2 ** n) for i in range(m+1) for i in range(m+1) i range(m+1) range m+1 m 1 for i in range(m+1) [10**18] * (2 ** n) [10**18] 10**18 10 18 2 ** n 2 n dp = [[10**18] * (2 ** n) for i in range(m+1)] dp [[10**18] * (2 ** n) for i in range(m+1)] dp[0][0] = 0 dp[0][0] [0] dp 0 0 0 for i,((a,b),c) in enumerate(zip(ab,c)):
  d = 0
  for x in c:
    d += 2 ** (x-1)
  for j in range(2**n):
    NEXT = j | d
    dp[i+1][j] = min(dp[i+1][j], dp[i][j])
    dp[i+1][NEXT] = min(dp[i+1][NEXT], dp[i][j]+a) i ((a,b),c) (a,b) a b c enumerate(zip(ab,c)) enumerate zip(ab,c) zip ab c d = 0 d 0 for x in c:
    d += 2 ** (x-1)
   x c d += 2 ** (x-1) d 2 ** (x-1) 2 x-1 x 1 for j in range(2**n):
    NEXT = j | d
    dp[i+1][j] = min(dp[i+1][j], dp[i][j])
    dp[i+1][NEXT] = min(dp[i+1][NEXT], dp[i][j]+a) j range(2**n) range 2**n 2 n NEXT = j | d NEXT j | d j d dp[i+1][j] = min(dp[i+1][j], dp[i][j]) dp[i+1][j] [i+1] dp i+1 i 1 j min(dp[i+1][j], dp[i][j]) min dp[i+1][j] [i+1] dp i+1 i 1 j dp[i][j] [i] dp i j dp[i+1][NEXT] = min(dp[i+1][NEXT], dp[i][j]+a) dp[i+1][NEXT] [i+1] dp i+1 i 1 NEXT min(dp[i+1][NEXT], dp[i][j]+a) min dp[i+1][NEXT] [i+1] dp i+1 i 1 NEXT dp[i][j]+a dp[i][j] [i] dp i j a ans = dp[m][2**n-1] ans dp[m][2**n-1] [m] dp m 2**n-1 2**n 2 n 1 if ans == 10 ** 18:
  print(-1)
else:
  print(ans) ans == 10 ** 18 ans 10 ** 18 10 18 print(-1) print -1 print(ans) print ans d += 2 ** (x-1) 2 ** (x-1) d c = [] [] c ans = dp[m][2**n-1] dp[m][2**n-1] ans m = map(int, input().split()) map(int, input().split()) m d = 0 0 d n,m = map(int, input().split()) map(int, input().split()) n dp = [[10**18] * (2 ** n) for i in range(m+1)] [[10**18] * (2 ** n) for i in range(m+1)] dp NEXT = j | d j | d NEXT ab = [] [] ab
n,m = map(int, input().split())
ab = []
c = []
for i in range(m):
  ab.append(list(map(int, input().split())))
  c.append(list(map(int, input().split())))
dp = [[10**18] * (2 ** n) for i in range(m+1)]
dp[0][0] = 0
for i,((a,b),c) in enumerate(zip(ab,c)):
  d = 0
  for x in c:
    d += 2 ** (x-1)
  for j in range(2**n):
    NEXT = j | d
    dp[i+1][j] = min(dp[i+1][j], dp[i][j])
    dp[i+1][NEXT] = min(dp[i+1][NEXT], dp[i][j]+a)
ans = dp[m][2**n-1]
if ans == 10 ** 18:
  print(-1)
else:
  print(ans)