import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    keys = []
    for _ in range(m):
        bit = ["0"] * n
        a, b = map(int, input().split())
        C = map(int, input().split())
        for c in C:
            bit[c - 1] = "1"
        bit = int("".join(bit), 2)
        keys.append([bit, a])

    dp = [f_inf] * (1 << n)
    dp[0] = 0
    for i in range(1 << n):
        for k, cost in keys:
            idx = i | k
            dp[idx] = min(dp[idx], dp[i] + cost)

    print(dp[-1] if dp[-1] != f_inf else -1)


if __name__ == '__main__':
    resolve() import sys sys sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline f_inf = float('inf') f_inf float('inf') float 'inf' mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 def resolve():
    n, m = map(int, input().split())
    keys = []
    for _ in range(m):
        bit = ["0"] * n
        a, b = map(int, input().split())
        C = map(int, input().split())
        for c in C:
            bit[c - 1] = "1"
        bit = int("".join(bit), 2)
        keys.append([bit, a])

    dp = [f_inf] * (1 << n)
    dp[0] = 0
    for i in range(1 << n):
        for k, cost in keys:
            idx = i | k
            dp[idx] = min(dp[idx], dp[i] + cost)

    print(dp[-1] if dp[-1] != f_inf else -1) resolve n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m keys = [] keys [] for _ in range(m):
        bit = ["0"] * n
        a, b = map(int, input().split())
        C = map(int, input().split())
        for c in C:
            bit[c - 1] = "1"
        bit = int("".join(bit), 2)
        keys.append([bit, a])

     _ range(m) range m bit = ["0"] * n bit ["0"] * n ["0"] "0" n a, b = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b C = map(int, input().split()) C map(int, input().split()) map int input().split() ().split () input split for c in C:
            bit[c - 1] = "1"
         c C bit[c - 1] = "1" bit[c - 1] bit c - 1 c 1 "1" bit = int("".join(bit), 2) bit int("".join(bit), 2) int "".join(bit) "".join "" join bit 2 keys.append([bit, a]) keys.append keys append [bit, a] bit a dp = [f_inf] * (1 << n) dp [f_inf] * (1 << n) [f_inf] f_inf 1 << n 1 n dp[0] = 0 dp[0] dp 0 0 for i in range(1 << n):
        for k, cost in keys:
            idx = i | k
            dp[idx] = min(dp[idx], dp[i] + cost)

     i range(1 << n) range 1 << n 1 n for k, cost in keys:
            idx = i | k
            dp[idx] = min(dp[idx], dp[i] + cost)

     k cost keys idx = i | k idx i | k i k dp[idx] = min(dp[idx], dp[i] + cost) dp[idx] dp idx min(dp[idx], dp[i] + cost) min dp[idx] dp idx dp[i] + cost dp[i] dp i cost print(dp[-1] if dp[-1] != f_inf else -1) print dp[-1] if dp[-1] != f_inf else -1 dp[-1] != f_inf dp[-1] dp -1 f_inf dp[-1] dp -1 -1 if __name__ == '__main__':
    resolve() __name__ == '__main__' __name__ '__main__' resolve() resolve input = sys.stdin.readline sys.stdin.readline input mod = 10 ** 9 + 7 10 ** 9 + 7 mod f_inf = float('inf') float('inf') f_inf def resolve():
    n, m = map(int, input().split())
    keys = []
    for _ in range(m):
        bit = ["0"] * n
        a, b = map(int, input().split())
        C = map(int, input().split())
        for c in C:
            bit[c - 1] = "1"
        bit = int("".join(bit), 2)
        keys.append([bit, a])

    dp = [f_inf] * (1 << n)
    dp[0] = 0
    for i in range(1 << n):
        for k, cost in keys:
            idx = i | k
            dp[idx] = min(dp[idx], dp[i] + cost)

    print(dp[-1] if dp[-1] != f_inf else -1) def resolve():
    n, m = map(int, input().split())
    keys = []
    for _ in range(m):
        bit = ["0"] * n
        a, b = map(int, input().split())
        C = map(int, input().split())
        for c in C:
            bit[c - 1] = "1"
        bit = int("".join(bit), 2)
        keys.append([bit, a])

    dp = [f_inf] * (1 << n)
    dp[0] = 0
    for i in range(1 << n):
        for k, cost in keys:
            idx = i | k
            dp[idx] = min(dp[idx], dp[i] + cost)

    print(dp[-1] if dp[-1] != f_inf else -1) resolve
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    keys = []
    for _ in range(m):
        bit = ["0"] * n
        a, b = map(int, input().split())
        C = map(int, input().split())
        for c in C:
            bit[c - 1] = "1"
        bit = int("".join(bit), 2)
        keys.append([bit, a])

    dp = [f_inf] * (1 << n)
    dp[0] = 0
    for i in range(1 << n):
        for k, cost in keys:
            idx = i | k
            dp[idx] = min(dp[idx], dp[i] + cost)

    print(dp[-1] if dp[-1] != f_inf else -1)


if __name__ == '__main__':
    resolve()
