N, M = list(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())))

A = [10 ** 10] * (1 << N)
C = []
for i in range(M):
  t = 0
  cc = c[i]
  a, b = ab[i]
  for j in cc:
    t |= 1 << (j - 1)
  C.append([t, a])
  A[t] = min(A[t], a)

for i in range(1, N + 1):
  n = (1 << i) - 1
  while n < (1 << N):
    for j in range(M):
      k, a = n | C[j][0], C[j][1]
      A[k] = min(A[k], A[n] + a)
    x = n & -n
    y = n + x
    n = ((n & ~y) // x >> 1) | y

if A[-1] == 10 ** 10:
  print(-1)
else:
  print(A[-1])
 N, M = list(map(int, input().split())) N list(map(int, input().split())) list 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 A = [10 ** 10] * (1 << N) A [10 ** 10] * (1 << N) [10 ** 10] 10 ** 10 10 10 1 << N 1 N C = [] C [] for i in range(M):
  t = 0
  cc = c[i]
  a, b = ab[i]
  for j in cc:
    t |= 1 << (j - 1)
  C.append([t, a])
  A[t] = min(A[t], a) i range(M) range M t = 0 t 0 cc = c[i] cc c[i] c i a, b = ab[i] a ab[i] ab i b for j in cc:
    t |= 1 << (j - 1)
   j cc t |= 1 << (j - 1) t 1 << (j - 1) 1 j - 1 j 1 C.append([t, a]) C.append C append [t, a] t a A[t] = min(A[t], a) A[t] A t min(A[t], a) min A[t] A t a for i in range(1, N + 1):
  n = (1 << i) - 1
  while n < (1 << N):
    for j in range(M):
      k, a = n | C[j][0], C[j][1]
      A[k] = min(A[k], A[n] + a)
    x = n & -n
    y = n + x
    n = ((n & ~y) // x >> 1) | y i range(1, N + 1) range 1 N + 1 N 1 n = (1 << i) - 1 n (1 << i) - 1 1 << i 1 i 1 while n < (1 << N):
    for j in range(M):
      k, a = n | C[j][0], C[j][1]
      A[k] = min(A[k], A[n] + a)
    x = n & -n
    y = n + x
    n = ((n & ~y) // x >> 1) | y n < (1 << N) n 1 << N 1 N for j in range(M):
      k, a = n | C[j][0], C[j][1]
      A[k] = min(A[k], A[n] + a)
     j range(M) range M k, a = n | C[j][0], C[j][1] k n | C[j][0] n C[j][0] [j] C j 0 a C[j][1] [j] C j 1 A[k] = min(A[k], A[n] + a) A[k] A k min(A[k], A[n] + a) min A[k] A k A[n] + a A[n] A n a x = n & -n x n & -n n -n n y = n + x y n + x n x n = ((n & ~y) // x >> 1) | y n ((n & ~y) // x >> 1) | y (n & ~y) // x >> 1 (n & ~y) // x n & ~y n ~y y x 1 y if A[-1] == 10 ** 10:
  print(-1)
else:
  print(A[-1]) A[-1] == 10 ** 10 A[-1] A -1 10 ** 10 10 10 print(-1) print -1 print(A[-1]) print A[-1] A -1 ab = [] [] ab a = n | C[j][0], C[j][1] C[j][1] a a, b = ab[i] ab[i] a n = ((n & ~y) // x >> 1) | y ((n & ~y) // x >> 1) | y n t |= 1 << (j - 1) 1 << (j - 1) t C = [] [] C cc = c[i] c[i] cc n = (1 << i) - 1 (1 << i) - 1 n x = n & -n n & -n x N, M = list(map(int, input().split())) list(map(int, input().split())) N A = [10 ** 10] * (1 << N) [10 ** 10] * (1 << N) A c = [] [] c b = ab[i] ab[i] b y = n + x n + x y k, a = n | C[j][0], C[j][1] n | C[j][0] k M = list(map(int, input().split())) list(map(int, input().split())) M t = 0 0 t
N, M = list(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())))

A = [10 ** 10] * (1 << N)
C = []
for i in range(M):
  t = 0
  cc = c[i]
  a, b = ab[i]
  for j in cc:
    t |= 1 << (j - 1)
  C.append([t, a])
  A[t] = min(A[t], a)

for i in range(1, N + 1):
  n = (1 << i) - 1
  while n < (1 << N):
    for j in range(M):
      k, a = n | C[j][0], C[j][1]
      A[k] = min(A[k], A[n] + a)
    x = n & -n
    y = n + x
    n = ((n & ~y) // x >> 1) | y

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

