INF = 10**9 + 7


def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M = (int(i) for i in input().split())
    A = []
    B = []
    C = []
    for _ in range(M):
        a, b = (int(i) for i in input().split())
        A.append(a)
        B.append(b)
        bit = 0
        for s in input().split():
            c = int(s)
            bit |= (1 << (c-1))
        C.append(bit)

    dp = [[INF]*(1 << N) for _ in range(M+1)]
    dp[0][0] = 0
    for i in range(M):
        for j in range(1 << N):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            if dp[i][j] != INF:
                next_bit = j | C[i]
                dp[i][next_bit] = min(dp[i][next_bit], dp[i][j] + A[i])
    ans = dp[M][(1 << N) - 1]
    if ans == INF:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main() INF = 10**9 + 7 INF 10**9 + 7 10**9 10 9 7 def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M = (int(i) for i in input().split())
    A = []
    B = []
    C = []
    for _ in range(M):
        a, b = (int(i) for i in input().split())
        A.append(a)
        B.append(b)
        bit = 0
        for s in input().split():
            c = int(s)
            bit |= (1 << (c-1))
        C.append(bit)

    dp = [[INF]*(1 << N) for _ in range(M+1)]
    dp[0][0] = 0
    for i in range(M):
        for j in range(1 << N):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            if dp[i][j] != INF:
                next_bit = j | C[i]
                dp[i][next_bit] = min(dp[i][next_bit], dp[i][j] + A[i])
    ans = dp[M][(1 << N) - 1]
    if ans == INF:
        print(-1)
    else:
        print(ans) main import sys sys input = sys.stdin.buffer.readline input sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i N, M = (int(i) for i in input().split()) N (int(i) for i in input().split()) M A = [] A [] B = [] B [] C = [] C [] for _ in range(M):
        a, b = (int(i) for i in input().split())
        A.append(a)
        B.append(b)
        bit = 0
        for s in input().split():
            c = int(s)
            bit |= (1 << (c-1))
        C.append(bit)

     _ range(M) range M int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a, b = (int(i) for i in input().split()) a (int(i) for i in input().split()) b A.append(a) A.append A append a B.append(b) B.append B append b bit = 0 bit 0 for s in input().split():
            c = int(s)
            bit |= (1 << (c-1))
         s input().split() ().split () input split c = int(s) c int(s) int s bit |= (1 << (c-1)) bit 1 << (c-1) 1 c-1 c 1 C.append(bit) C.append C append bit [INF]*(1 << 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]*(1 << N) [INF] INF 1 << N 1 N dp = [[INF]*(1 << N) for _ in range(M+1)] dp [[INF]*(1 << N) for _ in range(M+1)] dp[0][0] = 0 dp[0][0] [0] dp 0 0 0 for i in range(M):
        for j in range(1 << N):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            if dp[i][j] != INF:
                next_bit = j | C[i]
                dp[i][next_bit] = min(dp[i][next_bit], dp[i][j] + A[i])
     i range(M) range M for j in range(1 << N):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            if dp[i][j] != INF:
                next_bit = j | C[i]
                dp[i][next_bit] = min(dp[i][next_bit], dp[i][j] + A[i])
     j range(1 << N) range 1 << N 1 N 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 if dp[i][j] != INF:
                next_bit = j | C[i]
                dp[i][next_bit] = min(dp[i][next_bit], dp[i][j] + A[i])
     dp[i][j] != INF dp[i][j] [i] dp i j INF next_bit = j | C[i] next_bit j | C[i] j C[i] C i dp[i][next_bit] = min(dp[i][next_bit], dp[i][j] + A[i]) dp[i][next_bit] [i] dp i next_bit min(dp[i][next_bit], dp[i][j] + A[i]) min dp[i][next_bit] [i] dp i next_bit dp[i][j] + A[i] dp[i][j] [i] dp i j A[i] A i ans = dp[M][(1 << N) - 1] ans dp[M][(1 << N) - 1] [M] dp M (1 << N) - 1 1 << N 1 N 1 if ans == INF:
        print(-1)
    else:
        print(ans) ans == INF ans INF print(-1) print -1 print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M = (int(i) for i in input().split())
    A = []
    B = []
    C = []
    for _ in range(M):
        a, b = (int(i) for i in input().split())
        A.append(a)
        B.append(b)
        bit = 0
        for s in input().split():
            c = int(s)
            bit |= (1 << (c-1))
        C.append(bit)

    dp = [[INF]*(1 << N) for _ in range(M+1)]
    dp[0][0] = 0
    for i in range(M):
        for j in range(1 << N):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            if dp[i][j] != INF:
                next_bit = j | C[i]
                dp[i][next_bit] = min(dp[i][next_bit], dp[i][j] + A[i])
    ans = dp[M][(1 << N) - 1]
    if ans == INF:
        print(-1)
    else:
        print(ans) def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M = (int(i) for i in input().split())
    A = []
    B = []
    C = []
    for _ in range(M):
        a, b = (int(i) for i in input().split())
        A.append(a)
        B.append(b)
        bit = 0
        for s in input().split():
            c = int(s)
            bit |= (1 << (c-1))
        C.append(bit)

    dp = [[INF]*(1 << N) for _ in range(M+1)]
    dp[0][0] = 0
    for i in range(M):
        for j in range(1 << N):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            if dp[i][j] != INF:
                next_bit = j | C[i]
                dp[i][next_bit] = min(dp[i][next_bit], dp[i][j] + A[i])
    ans = dp[M][(1 << N) - 1]
    if ans == INF:
        print(-1)
    else:
        print(ans) main INF = 10**9 + 7 10**9 + 7 INF
INF = 10**9 + 7


def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M = (int(i) for i in input().split())
    A = []
    B = []
    C = []
    for _ in range(M):
        a, b = (int(i) for i in input().split())
        A.append(a)
        B.append(b)
        bit = 0
        for s in input().split():
            c = int(s)
            bit |= (1 << (c-1))
        C.append(bit)

    dp = [[INF]*(1 << N) for _ in range(M+1)]
    dp[0][0] = 0
    for i in range(M):
        for j in range(1 << N):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            if dp[i][j] != INF:
                next_bit = j | C[i]
                dp[i][next_bit] = min(dp[i][next_bit], dp[i][j] + A[i])
    ans = dp[M][(1 << N) - 1]
    if ans == INF:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()
