N, M = map(int, input().split())
AB = []
C = []
for _ in range(M):
    AB.append(list(map(int, input().split())))
    C.append(list(map(int, input().split())))

INF = 10 ** 9 + 7
dp = [INF] * (2 ** N)
dp[0] = 0

for i, ((a, b), c) in enumerate(zip(AB, C)):
    num = int("".join(["01"[int(i + 1 in c)] for i in range(N)]), 2)
    for j in range(2 ** N):
        dp[j | num] = min(dp[j | num], dp[j] + a)

print(dp[-1] if dp[-1] < INF else -1) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M AB = [] AB [] C = [] C [] for _ in range(M):
    AB.append(list(map(int, input().split())))
    C.append(list(map(int, input().split()))) _ 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 INF = 10 ** 9 + 7 INF 10 ** 9 + 7 10 ** 9 10 9 7 dp = [INF] * (2 ** N) dp [INF] * (2 ** N) [INF] INF 2 ** N 2 N dp[0] = 0 dp[0] dp 0 0 for i, ((a, b), c) in enumerate(zip(AB, C)):
    num = int("".join(["01"[int(i + 1 in c)] for i in range(N)]), 2)
    for j in range(2 ** N):
        dp[j | num] = min(dp[j | num], dp[j] + a) i ((a, b), c) (a, b) a b c enumerate(zip(AB, C)) enumerate zip(AB, C) zip AB C "01"[int(i + 1 in c)] for i in range(N) for i in range(N) i range(N) range N for i in range(N) "01"[int(i + 1 in c)] "01" int(i + 1 in c) int i + 1 in c i + 1 i 1 c num = int("".join(["01"[int(i + 1 in c)] for i in range(N)]), 2) num int("".join(["01"[int(i + 1 in c)] for i in range(N)]), 2) int "".join(["01"[int(i + 1 in c)] for i in range(N)]) "".join "" join ["01"[int(i + 1 in c)] for i in range(N)] 2 for j in range(2 ** N):
        dp[j | num] = min(dp[j | num], dp[j] + a) j range(2 ** N) range 2 ** N 2 N dp[j | num] = min(dp[j | num], dp[j] + a) dp[j | num] dp j | num j num min(dp[j | num], dp[j] + a) min dp[j | num] dp j | num j num dp[j] + a dp[j] dp j a print(dp[-1] if dp[-1] < INF else -1) print dp[-1] if dp[-1] < INF else -1 dp[-1] < INF dp[-1] dp -1 INF dp[-1] dp -1 -1 C = [] [] C M = map(int, input().split()) map(int, input().split()) M dp = [INF] * (2 ** N) [INF] * (2 ** N) dp N, M = map(int, input().split()) map(int, input().split()) N num = int("".join(["01"[int(i + 1 in c)] for i in range(N)]), 2) int("".join(["01"[int(i + 1 in c)] for i in range(N)]), 2) num INF = 10 ** 9 + 7 10 ** 9 + 7 INF AB = [] [] AB
N, M = map(int, input().split())
AB = []
C = []
for _ in range(M):
    AB.append(list(map(int, input().split())))
    C.append(list(map(int, input().split())))

INF = 10 ** 9 + 7
dp = [INF] * (2 ** N)
dp[0] = 0

for i, ((a, b), c) in enumerate(zip(AB, C)):
    num = int("".join(["01"[int(i + 1 in c)] for i in range(N)]), 2)
    for j in range(2 ** N):
        dp[j | num] = min(dp[j | num], dp[j] + a)

print(dp[-1] if dp[-1] < INF else -1)
