import sys





def solve():

    input = sys.stdin.readline

    mod = 10 ** 9 + 7

    n, m = list(map(int, input().rstrip('\n').split()))

    pw = 2 ** n

    dp = [10 ** 20] * pw

    dp[0] = 0

    for i in range(m):

        a, b = list(map(int, input().rstrip('\n').split()))

        c = sum(2 ** (i - 1) for i in list(map(int, input().rstrip('\n').split())))

        for j in range(pw):

            if dp[j | c] > dp[j] + a:

                dp[j | c] = dp[j] + a

    if dp[-1] == 10 ** 20:

        print((-1))

    else:

        print((dp[-1]))





if __name__ == '__main__':

    solve()

import sys





def solve():

    input = sys.stdin.readline

    mod = 10 ** 9 + 7

    n, m = list(map(int, input().rstrip('\n').split()))

    pw = pow(2, n)

    dp = [10 ** 15] * pw

    dp[0] = 0

    for _ in range(m):

        a, b = list(map(int, input().rstrip('\n').split()))

        c = sum(2 ** (i - 1) for i in list(map(int, input().rstrip('\n').split())))

        for i in range(pw):

            dp[c | i] = min(dp[c | i], dp[i] + a)

    print((dp[-1] if dp[-1] != 10 ** 15 else -1))





if __name__ == '__main__':

    solve()

import sys


def solve():
    input = sys.stdin.readline
    mod = 10**9 + 7
    n, m = list(map(int, input().rstrip("\n").split()))
    pw = 2**n
    dp = [10**20] * pw
    dp[0] = 0
    for i in range(m):
        a, b = list(map(int, input().rstrip("\n").split()))
        c = sum(2 ** (i - 1) for i in list(map(int, input().rstrip("\n").split())))
        for j in range(pw):
            if dp[j | c] > dp[j] + a:
                dp[j | c] = dp[j] + a
    if dp[-1] == 10**20:
        print((-1))
    else:
        print((dp[-1]))


if __name__ == "__main__":
    solve()

import sys


def solve():
    input = sys.stdin.readline
    mod = 10**9 + 7
    n, m = list(map(int, input().rstrip("\n").split()))
    pw = pow(2, n)
    dp = [10**15] * pw
    dp[0] = 0
    for _ in range(m):
        a, b = list(map(int, input().rstrip("\n").split()))
        c = sum(2 ** (i - 1) for i in list(map(int, input().rstrip("\n").split())))
        for i in range(pw):
            dp[c | i] = min(dp[c | i], dp[i] + a)
    print((dp[-1] if dp[-1] != 10**15 else -1))


if __name__ == "__main__":
    solve()

-    pw = 2**n -    dp = [10**20] * pw +    pw = pow(2, n) +    dp = [10**15] * pw -    for i in range(m): +    for _ in range(m): -        for j in range(pw): -            if dp[j | c] > dp[j] + a: -                dp[j | c] = dp[j] + a -    if dp[-1] == 10**20: -        print((-1)) -    else: -        print((dp[-1])) +        for i in range(pw): +            dp[c | i] = min(dp[c | i], dp[i] + a) +    print((dp[-1] if dp[-1] != 10**15 else -1))