import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, long M, long[] a, long[] b, long[] k, long g) {
    auto dp = new long[][](M + 1, 2 ^^ N);
    foreach (i; 0 .. M + 1)
        foreach (p; 0 .. 2 ^^ N)
            dp[i][p] = long.max;
    
    dp[0][0] = 0;
    foreach (i; 0 .. M) {
        foreach (p; 0 .. 2 ^^ N) {
            if (dp[i][p] == long.max)
                continue;
            
            dp[i + 1][p] = min(dp[i + 1][p], dp[i][p]);
            dp[i + 1][p | k[i]] = min(dp[i + 1][p | k[i]], dp[i][p] + a[i]);
        }
    }

    return dp[M][g] == long.max ? -1 : dp[M][g];
}


void main() {
    auto l1 = readln.chomp.split.map!(to!long).array;
    long N = l1[0];
    long M = l1[1];

    auto g = goalPattern(N);

    auto a = new long[](M);
    auto b = new long[](M);
    auto k = new long[](M);
    foreach (i; 0 .. M) {
        auto l2 = readln.chomp.split.map!(to!long).array;
        a[i] = l2[0];
        b[i] = l2[1];
        k[i] = readln.chomp.split.map!(to!long).array.keyPattern;
    }

    solve(N, M, a, b, k, g).writeln;
}


long keyPattern(long[] c) {
    long key;
    foreach (ci; c) {
        key += 2 ^^ (ci - 1);
    }
    return key;
}

long goalPattern(long N) {
    return 2 ^^ N - 1;
}
