import sys
input = sys.stdin.readline


def pack(C):
    bitmask = 0
    for c in C:
        d = 1 << (c-1)
        bitmask |= d
    return bitmask


def read():
    N, M = list(map(int, input().strip().split()))
    A = list()
    C = list()
    for i in range(M):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        c = map(int, input().strip().split())
        C.append(pack(c))
    return N, M, A, C


def solve(N, M, A, C, INF=10**9):
    # dp[state][i]: i本の鍵[0, i)を使って状態stateにするための最小コスト
    n_states = 1 << N
    end_state = n_states - 1
    dp = [[INF for j in range(2)] for state in range(n_states)]
    dp[0][0] = 0
    dp[0][1] = 0

    for j in range(M):
        m0 = j & 1
        m1 = 1 - m0
        for state in range(n_states):
            next_state = state | C[j]
            dp[state][m1] = min(dp[state][m1], dp[state][m0])
            if next_state > state:
                dp[next_state][m1] = min(dp[next_state][m1], dp[state][m0] + A[j])
    
    m0 = M & 1
    return dp[end_state][m0] if dp[end_state][m0] != INF else -1


if __name__ == "__main__":
    inputs = read()
    print("%s" % solve(*inputs)) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def pack(C):
    bitmask = 0
    for c in C:
        d = 1 << (c-1)
        bitmask |= d
    return bitmask pack bitmask = 0 bitmask 0 for c in C:
        d = 1 << (c-1)
        bitmask |= d
     c C d = 1 << (c-1) d 1 << (c-1) 1 c-1 c 1 bitmask |= d bitmask d return bitmask bitmask C C def read():
    N, M = list(map(int, input().strip().split()))
    A = list()
    C = list()
    for i in range(M):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        c = map(int, input().strip().split())
        C.append(pack(c))
    return N, M, A, C read N, M = list(map(int, input().strip().split())) N list(map(int, input().strip().split())) list map(int, input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split M A = list() A list() list C = list() C list() list for i in range(M):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        c = map(int, input().strip().split())
        C.append(pack(c))
     i range(M) range M a, b = list(map(int, input().strip().split())) a list(map(int, input().strip().split())) list map(int, input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split b A.append(a) A.append A append a c = map(int, input().strip().split()) c map(int, input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split C.append(pack(c)) C.append C append pack(c) pack c return N, M, A, C return N, M, A, C N M A C def solve(N, M, A, C, INF=10**9):
    # dp[state][i]: i本の鍵[0, i)を使って状態stateにするための最小コスト
    n_states = 1 << N
    end_state = n_states - 1
    dp = [[INF for j in range(2)] for state in range(n_states)]
    dp[0][0] = 0
    dp[0][1] = 0

    for j in range(M):
        m0 = j & 1
        m1 = 1 - m0
        for state in range(n_states):
            next_state = state | C[j]
            dp[state][m1] = min(dp[state][m1], dp[state][m0])
            if next_state > state:
                dp[next_state][m1] = min(dp[next_state][m1], dp[state][m0] + A[j])
    
    m0 = M & 1
    return dp[end_state][m0] if dp[end_state][m0] != INF else -1 solve n_states = 1 << N n_states 1 << N 1 N end_state = n_states - 1 end_state n_states - 1 n_states 1 [INF for j in range(2)] for state in range(n_states) for state in range(n_states) state range(n_states) range n_states for state in range(n_states) [INF for j in range(2)] dp = [[INF for j in range(2)] for state in range(n_states)] dp [[INF for j in range(2)] for state in range(n_states)] dp[0][0] = 0 dp[0][0] [0] dp 0 0 0 dp[0][1] = 0 dp[0][1] [0] dp 0 1 0 for j in range(M):
        m0 = j & 1
        m1 = 1 - m0
        for state in range(n_states):
            next_state = state | C[j]
            dp[state][m1] = min(dp[state][m1], dp[state][m0])
            if next_state > state:
                dp[next_state][m1] = min(dp[next_state][m1], dp[state][m0] + A[j])
    
     j range(M) range M m0 = j & 1 m0 j & 1 j 1 m1 = 1 - m0 m1 1 - m0 1 m0 for state in range(n_states):
            next_state = state | C[j]
            dp[state][m1] = min(dp[state][m1], dp[state][m0])
            if next_state > state:
                dp[next_state][m1] = min(dp[next_state][m1], dp[state][m0] + A[j])
    
     state range(n_states) range n_states next_state = state | C[j] next_state state | C[j] state C[j] C j dp[state][m1] = min(dp[state][m1], dp[state][m0]) dp[state][m1] [state] dp state m1 min(dp[state][m1], dp[state][m0]) min dp[state][m1] [state] dp state m1 dp[state][m0] [state] dp state m0 if next_state > state:
                dp[next_state][m1] = min(dp[next_state][m1], dp[state][m0] + A[j])
    
     next_state > state next_state state dp[next_state][m1] = min(dp[next_state][m1], dp[state][m0] + A[j]) dp[next_state][m1] [next_state] dp next_state m1 min(dp[next_state][m1], dp[state][m0] + A[j]) min dp[next_state][m1] [next_state] dp next_state m1 dp[state][m0] + A[j] dp[state][m0] [state] dp state m0 A[j] A j m0 = M & 1 m0 M & 1 M 1 return dp[end_state][m0] if dp[end_state][m0] != INF else -1 dp[end_state][m0] if dp[end_state][m0] != INF else -1 dp[end_state][m0] != INF dp[end_state][m0] [end_state] dp end_state m0 INF dp[end_state][m0] [end_state] dp end_state m0 -1 N N M M A A C C INF=10**9 INF 10**9 10 9 if __name__ == "__main__":
    inputs = read()
    print("%s" % solve(*inputs)) __name__ == "__main__" __name__ "__main__" inputs = read() inputs read() read print("%s" % solve(*inputs)) print "%s" % solve(*inputs) "%s" solve(*inputs) solve *inputs inputs inputs = read() read() inputs def solve(N, M, A, C, INF=10**9):
    # dp[state][i]: i本の鍵[0, i)を使って状態stateにするための最小コスト
    n_states = 1 << N
    end_state = n_states - 1
    dp = [[INF for j in range(2)] for state in range(n_states)]
    dp[0][0] = 0
    dp[0][1] = 0

    for j in range(M):
        m0 = j & 1
        m1 = 1 - m0
        for state in range(n_states):
            next_state = state | C[j]
            dp[state][m1] = min(dp[state][m1], dp[state][m0])
            if next_state > state:
                dp[next_state][m1] = min(dp[next_state][m1], dp[state][m0] + A[j])
    
    m0 = M & 1
    return dp[end_state][m0] if dp[end_state][m0] != INF else -1 def solve(N, M, A, C, INF=10**9):
    # dp[state][i]: i本の鍵[0, i)を使って状態stateにするための最小コスト
    n_states = 1 << N
    end_state = n_states - 1
    dp = [[INF for j in range(2)] for state in range(n_states)]
    dp[0][0] = 0
    dp[0][1] = 0

    for j in range(M):
        m0 = j & 1
        m1 = 1 - m0
        for state in range(n_states):
            next_state = state | C[j]
            dp[state][m1] = min(dp[state][m1], dp[state][m0])
            if next_state > state:
                dp[next_state][m1] = min(dp[next_state][m1], dp[state][m0] + A[j])
    
    m0 = M & 1
    return dp[end_state][m0] if dp[end_state][m0] != INF else -1 solve def read():
    N, M = list(map(int, input().strip().split()))
    A = list()
    C = list()
    for i in range(M):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        c = map(int, input().strip().split())
        C.append(pack(c))
    return N, M, A, C def read():
    N, M = list(map(int, input().strip().split()))
    A = list()
    C = list()
    for i in range(M):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        c = map(int, input().strip().split())
        C.append(pack(c))
    return N, M, A, C read input = sys.stdin.readline sys.stdin.readline input def pack(C):
    bitmask = 0
    for c in C:
        d = 1 << (c-1)
        bitmask |= d
    return bitmask def pack(C):
    bitmask = 0
    for c in C:
        d = 1 << (c-1)
        bitmask |= d
    return bitmask pack
import sys
input = sys.stdin.readline


def pack(C):
    bitmask = 0
    for c in C:
        d = 1 << (c-1)
        bitmask |= d
    return bitmask


def read():
    N, M = list(map(int, input().strip().split()))
    A = list()
    C = list()
    for i in range(M):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        c = map(int, input().strip().split())
        C.append(pack(c))
    return N, M, A, C


def solve(N, M, A, C, INF=10**9):
    # dp[state][i]: i本の鍵[0, i)を使って状態stateにするための最小コスト
    n_states = 1 << N
    end_state = n_states - 1
    dp = [[INF for j in range(2)] for state in range(n_states)]
    dp[0][0] = 0
    dp[0][1] = 0

    for j in range(M):
        m0 = j & 1
        m1 = 1 - m0
        for state in range(n_states):
            next_state = state | C[j]
            dp[state][m1] = min(dp[state][m1], dp[state][m0])
            if next_state > state:
                dp[next_state][m1] = min(dp[next_state][m1], dp[state][m0] + A[j])
    
    m0 = M & 1
    return dp[end_state][m0] if dp[end_state][m0] != INF else -1


if __name__ == "__main__":
    inputs = read()
    print("%s" % solve(*inputs))
