# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, M, ABCi):
    inf = 10 ** 5 * 12 * 2
    for i in range(M):
        C = ABCi[i][2]
        ABCi[i][2] = sum([2 ** (c - 1) for c in C])
    # dp[i番目までのカギだけ購入したときに][bin(j)の宝箱が開けられる最小金額]
    dp = [[inf] * (2 ** N) for _ in range(M + 1)]
    dp[0][0] = 0
    for i in range(1, M + 1):
        for j in range(2 ** N):
            a, b, c = ABCi[i - 1]
            dp[i][j] = min(dp[i - 1][(c & j) ^ j] + a, dp[i - 1][j])
    ans = min([x[2 ** N - 1] for x in dp])
    if ans == inf:
        ans = -1
    print(ans)


if __name__ == '__main__':
    N, M = map(int, input().split())
    ABCi = [
        [int(i) for i in input().split()] + [[int(i) for i in input().split()]]
        for _ in range(M)]
    solve(N, M, ABCi)

    # # test
    # from random import randint, sample
    # from func import random_str
    # N, M = 12, 10 ** 3
    # tmp = [i for i in range(1, N + 1)]
    # ABCi = [[randint(1, 10 ** 5), randint(1, N)] for _ in range(M)]
    # print(ABCi)
    # for i in range(M):
    #     ABCi[i].append(sample(tmp, ABCi[i][1]))
    # solve(N, M, ABCi) def solve(N, M, ABCi):
    inf = 10 ** 5 * 12 * 2
    for i in range(M):
        C = ABCi[i][2]
        ABCi[i][2] = sum([2 ** (c - 1) for c in C])
    # dp[i番目までのカギだけ購入したときに][bin(j)の宝箱が開けられる最小金額]
    dp = [[inf] * (2 ** N) for _ in range(M + 1)]
    dp[0][0] = 0
    for i in range(1, M + 1):
        for j in range(2 ** N):
            a, b, c = ABCi[i - 1]
            dp[i][j] = min(dp[i - 1][(c & j) ^ j] + a, dp[i - 1][j])
    ans = min([x[2 ** N - 1] for x in dp])
    if ans == inf:
        ans = -1
    print(ans) solve inf = 10 ** 5 * 12 * 2 inf 10 ** 5 * 12 * 2 10 ** 5 * 12 10 ** 5 10 5 12 2 for i in range(M):
        C = ABCi[i][2]
        ABCi[i][2] = sum([2 ** (c - 1) for c in C])
    # dp[i番目までのカギだけ購入したときに][bin(j)の宝箱が開けられる最小金額]
     i range(M) range M C = ABCi[i][2] C ABCi[i][2] [i] ABCi i 2 2 ** (c - 1) for c in C for c in C c C for c in C 2 ** (c - 1) 2 c - 1 c 1 ABCi[i][2] = sum([2 ** (c - 1) for c in C]) ABCi[i][2] [i] ABCi i 2 sum([2 ** (c - 1) for c in C]) sum [2 ** (c - 1) for c in C] [inf] * (2 ** N) for _ in range(M + 1) for _ in range(M + 1) _ range(M + 1) range M + 1 M 1 for _ in range(M + 1) [inf] * (2 ** N) [inf] inf 2 ** N 2 N dp = [[inf] * (2 ** N) for _ in range(M + 1)] dp [[inf] * (2 ** N) for _ in range(M + 1)] dp[0][0] = 0 dp[0][0] [0] dp 0 0 0 for i in range(1, M + 1):
        for j in range(2 ** N):
            a, b, c = ABCi[i - 1]
            dp[i][j] = min(dp[i - 1][(c & j) ^ j] + a, dp[i - 1][j])
     i range(1, M + 1) range 1 M + 1 M 1 for j in range(2 ** N):
            a, b, c = ABCi[i - 1]
            dp[i][j] = min(dp[i - 1][(c & j) ^ j] + a, dp[i - 1][j])
     j range(2 ** N) range 2 ** N 2 N a, b, c = ABCi[i - 1] a ABCi[i - 1] ABCi i - 1 i 1 b c dp[i][j] = min(dp[i - 1][(c & j) ^ j] + a, dp[i - 1][j]) dp[i][j] [i] dp i j min(dp[i - 1][(c & j) ^ j] + a, dp[i - 1][j]) min dp[i - 1][(c & j) ^ j] + a dp[i - 1][(c & j) ^ j] [i - 1] dp i - 1 i 1 (c & j) ^ j c & j c j j a dp[i - 1][j] [i - 1] dp i - 1 i 1 j x[2 ** N - 1] for x in dp for x in dp x dp for x in dp x[2 ** N - 1] x 2 ** N - 1 2 ** N 2 N 1 ans = min([x[2 ** N - 1] for x in dp]) ans min([x[2 ** N - 1] for x in dp]) min [x[2 ** N - 1] for x in dp] if ans == inf:
        ans = -1
     ans == inf ans inf ans = -1 ans -1 print(ans) print ans N N M M ABCi ABCi if __name__ == '__main__':
    N, M = map(int, input().split())
    ABCi = [
        [int(i) for i in input().split()] + [[int(i) for i in input().split()]]
        for _ in range(M)]
    solve(N, M, ABCi)

    # # test
    # from random import randint, sample
    # from func import random_str
    # N, M = 12, 10 ** 3
    # tmp = [i for i in range(1, N + 1)]
    # ABCi = [[randint(1, 10 ** 5), randint(1, N)] for _ in range(M)]
    # print(ABCi)
    # for i in range(M):
    #     ABCi[i].append(sample(tmp, ABCi[i][1]))
    # solve(N, M, ABCi) __name__ == '__main__' __name__ '__main__' N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M [int(i) for i in input().split()] + [[int(i) for i in input().split()]]
        for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) [int(i) for i in input().split()] + [[int(i) for i in input().split()]] [int(i) for i in input().split()] [[int(i) for i in input().split()]] [int(i) for i in input().split()] ABCi = [
        [int(i) for i in input().split()] + [[int(i) for i in input().split()]]
        for _ in range(M)] ABCi [
        [int(i) for i in input().split()] + [[int(i) for i in input().split()]]
        for _ in range(M)] solve(N, M, ABCi) solve N M ABCi M = map(int, input().split()) map(int, input().split()) M def solve(N, M, ABCi):
    inf = 10 ** 5 * 12 * 2
    for i in range(M):
        C = ABCi[i][2]
        ABCi[i][2] = sum([2 ** (c - 1) for c in C])
    # dp[i番目までのカギだけ購入したときに][bin(j)の宝箱が開けられる最小金額]
    dp = [[inf] * (2 ** N) for _ in range(M + 1)]
    dp[0][0] = 0
    for i in range(1, M + 1):
        for j in range(2 ** N):
            a, b, c = ABCi[i - 1]
            dp[i][j] = min(dp[i - 1][(c & j) ^ j] + a, dp[i - 1][j])
    ans = min([x[2 ** N - 1] for x in dp])
    if ans == inf:
        ans = -1
    print(ans) def solve(N, M, ABCi):
    inf = 10 ** 5 * 12 * 2
    for i in range(M):
        C = ABCi[i][2]
        ABCi[i][2] = sum([2 ** (c - 1) for c in C])
    # dp[i番目までのカギだけ購入したときに][bin(j)の宝箱が開けられる最小金額]
    dp = [[inf] * (2 ** N) for _ in range(M + 1)]
    dp[0][0] = 0
    for i in range(1, M + 1):
        for j in range(2 ** N):
            a, b, c = ABCi[i - 1]
            dp[i][j] = min(dp[i - 1][(c & j) ^ j] + a, dp[i - 1][j])
    ans = min([x[2 ** N - 1] for x in dp])
    if ans == inf:
        ans = -1
    print(ans) solve N, M = map(int, input().split()) map(int, input().split()) N ABCi = [
        [int(i) for i in input().split()] + [[int(i) for i in input().split()]]
        for _ in range(M)] [
        [int(i) for i in input().split()] + [[int(i) for i in input().split()]]
        for _ in range(M)] ABCi
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, M, ABCi):
    inf = 10 ** 5 * 12 * 2
    for i in range(M):
        C = ABCi[i][2]
        ABCi[i][2] = sum([2 ** (c - 1) for c in C])
    # dp[i番目までのカギだけ購入したときに][bin(j)の宝箱が開けられる最小金額]
    dp = [[inf] * (2 ** N) for _ in range(M + 1)]
    dp[0][0] = 0
    for i in range(1, M + 1):
        for j in range(2 ** N):
            a, b, c = ABCi[i - 1]
            dp[i][j] = min(dp[i - 1][(c & j) ^ j] + a, dp[i - 1][j])
    ans = min([x[2 ** N - 1] for x in dp])
    if ans == inf:
        ans = -1
    print(ans)


if __name__ == '__main__':
    N, M = map(int, input().split())
    ABCi = [
        [int(i) for i in input().split()] + [[int(i) for i in input().split()]]
        for _ in range(M)]
    solve(N, M, ABCi)

    # # test
    # from random import randint, sample
    # from func import random_str
    # N, M = 12, 10 ** 3
    # tmp = [i for i in range(1, N + 1)]
    # ABCi = [[randint(1, 10 ** 5), randint(1, N)] for _ in range(M)]
    # print(ABCi)
    # for i in range(M):
    #     ABCi[i].append(sample(tmp, ABCi[i][1]))
    # solve(N, M, ABCi)
