/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100100;
const int MOD = 1000000007;
const int inf = 1001001001;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

int gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

//dp[i][S] : i個目までの鍵を使った時、宝箱の状況Sを満たす最小のコスト
int dp[1005][(1<<12)+1];
vector<vector<int>> open(1005);
vector<int> price(1005);

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N,M;cin >> N >> M;
    for(int i = 0;i<M;i++){
        int p,openCount;cin >> p >> openCount;
        price.at(i) = p;
        for(int j = 0;j<openCount;j++){
            int openIndex;cin >> openIndex;openIndex--;
            open.at(i).push_back(openIndex);
        }
    }
    for(int i = 0;i<1005;i++)for(int j = 0;j<(1<<12)+1;j++)dp[i][j] = inf;
    dp[0][0] = 0;

    //鍵全探索
    for(int i = 0;i<M;i++){
        //i個目の鍵を使ったとき、開けられる宝箱をそれぞれ独立に考える
        for(int j = 0;j<open.at(i).size();j++){
            int OPENindex = open.at(i).at(j);
            int COST = price.at(i);
            int keys = 0;
            //i個目の鍵で開けられる箱をbitで管理
            for(int k = 0;k<open.at(i).size();k++){
                keys |= (1<<open.at(i).at(k));
            }
            //宝箱の状況Sを全探索
            for(int k = 0;k<(1<<N);k++){
                //Sの状況から鍵を使う（OR演算する！！！）
                dp[i+1][(k | keys)] = min(dp[i+1][(k | keys)],dp[i][k]+COST);
                //cout << k << " " << OPENindex << endl;
            }
        }
        for(int j = 0;j<(1<<N);j++){
            dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
        }
    }
    
    /*
    for(int i = 0;i<=M;i++){
        for(int j = 0;j<(1<<N);j++){
            if(dp[i][j] == inf) cout << "inf" << " ";
            else cout << dp[i][j] << " ";
        }
        cout << endl;
    }*/
    if(dp[M][(1<<N)-1] == inf){
        cout << -1 << endl;
    }
    else{
        cout << dp[M][(1<<N)-1] << endl;
    }
    
}


Measured memory_bytes: 19792