import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n, m;
    readf("%s %s", &n, &m);
    readln;

    struct key {
        int cost;
        int[] boxes;
    }
    
    key[] keys;
    foreach (_; 0 .. m) {
        int a, b;
        readf("%s %s", &a, &b);
        readln;
        
        auto arr = readln.chomp.split.map!(to!int).map!(x => x-1).array;
        
        keys ~= key(a, arr);
    }
    
    debug { keys.writeln; }
    
    auto unlockable = new bool[] (n);
    foreach (k; keys) {
        foreach (e; k.boxes) { unlockable[e] = true; }
    }
    if (!unlockable.all()) {
        writeln(-1);
        return;
    }
    
    immutable int INF = 10 ^^ 5 * 100;
    
    auto dp = new int[] (1 << n);
    dp[] = INF;
    dp[(1 << n) - 1] = 0;
    
    int unlock(int cur, int[] nrs) {
        debug { writeln(cur, ' ', nrs); }
        
        foreach (e; nrs) { cur |= (1 << e); }
        
        debug { writeln(cur); }
        
        return cur;
    }
    
    auto ord = (1 << n).iota.array.sort!((a, b) => a.popcnt() > b.popcnt()).array;
    
    debug { ord.writeln; }
    
    foreach (v; ord.dropOne) {
        foreach (e; keys) {
            dp[v] = min(dp[v], dp[unlock(v, e.boxes)] + e.cost);
        }
    }
    
    dp[0].writeln;
}