stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<vector>

using namespace std;

const int N=1e5+10;

typedef long long LL;



vector<int> v[N];

int a[N];

int b[N];



int dp[1<<15];



int main()

{

    int n,m;

    cin>>n>>m;

    for(int i=1;i<=m;i++)

    {

        cin>>a[i];

        int c;

        cin>>c;

        for(int j=1;j<=c;j++)   

        {

            int u;

            cin>>u;

            u--;

            b[i]|=(1<<u);

        }

        //cout<<b[i]<<endl;

    }





    for(int i=1;i<=m;i++)

    {

        int u=b[i];



        for(int j=0;j<(1<<n);j++)

        {

            if(j==0||dp[j])

            {

                if(dp[u|j])

                {

                    dp[u|j]=min(dp[u|j],dp[j]+a[i]);

                }

                else

                {

                    dp[u|j]=dp[j]+a[i];

                }

            }

        }

    }



    if(dp[(1<<n)-1])

        cout<<dp[(1<<n)-1]<<endl;

    else

        cout<<-1<<endl;

    



    

    //system("pause");

}

// Faster C++ solution for the same problem (measured speedup: 3.3588728572801796x):
#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int mod=1e9+7;

ll m,n,yy[3005],money[3005],dp[10005],vis[20]; 



int main()

{

    std::ios::sync_with_stdio(0); std::cin.tie(0);

    cin>>m>>n;

    for(int i=1;i<=5000;++i) dp[i]=1e15;

    ll a=1<<m,b,c;

    for(int i=0;i<n;++i)

    {

    	cin>>money[i]>>yy[i];

    	ll s=0;

    	for(int j=1;j<=yy[i];++j) 

    	{

    		cin>>b;vis[b]=1;

    		s+=1<<(b-1);

		}

		yy[i]=s;

	}

	for(int i=1;i<=m;++i) if(!vis[i]) {cout<<-1; return 0;} 

	for(int i=0;i<a-1;++i)

	{

		for(int j=0;j<n;++j)

		{

			dp[i|yy[j]]=min(dp[i|yy[j]],dp[i]+money[j]);

		}

	}

	cout<<dp[a-1];

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



#ifdef NeverBeRed

#include "debug.h"

#else

#define debug(...) 9715

#endif

typedef long long ll;

typedef long double ld;

typedef complex<ll> point;

#define F first

#define S second



struct info

{

	int c, m;

};



int main()

{

	#ifdef TurnRed

		//freopen("a.in", "r", stdin);

		//freopen("a.out", "w", stdout);

	#endif



	ios_base::sync_with_stdio(0), cin.tie(0);



	int n, m;

	cin >> n >> m;

	vector<info> a;

	for (int k; m--; )

	{

		a.push_back({ 0, 0 });

		cin >> a.back().c >> k;

		for (int i = 0, x; i < k; ++i)

		{

			cin >> x;

			a.back().m |= 1<<(x-1);

		}

	}



	vector<int> dp(1<<n, 1e9);

	dp[0] = 0;

	for (int i = 0; i < 1<<n; ++i)

		for (auto j : a)

			dp[i | j.m] = min(dp[i | j.m], dp[i] + j.c);



	int ans = dp[(1<<n)-1];

	if (ans >= 1e9) ans = -1;

	cout << ans << "\n";



	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.315821631841681x):
#include<cstring>

#include<algorithm>

#include<cstdio>

#define N 10005

#define INF 0x3f3f3f3f

using namespace std;

long long int d[N];

long long int a[1005];

int v[15];

int s[10005];

int b[1005];

int c[15];

int n;

int m;

int tar;

long long int ans=INF;

int main(){

scanf("%d%d",&n,&m);

//for(int i=1;i<=n;i++){

//l[i][0]=0;

//}

memset(d,0x3f,sizeof(d));

memset(v,0,sizeof(v));

memset(s,0,sizeof(s));



for(int i=1;i<=m;i++){

int x,y;

scanf("%lld%d",&a[i],&y);

int st=0;

for(int j=1;j<=y;j++){

scanf("%d",&c[j]);

v[c[j]]++;

st+=(1<<(c[j]-1));

}

b[i]=st;

}

tar=0;

for(int i=1;i<=n;i++){

tar+=(1<<(i-1));

if(v[i]==0){

printf("-1");

return 0;

}

}

d[0]=0;

for(int i=0;i<=tar;i++){

for(int j=1;j<=m;j++){

if(d[i|b[j]]>d[i]+a[j]){

d[i|b[j]]=d[i]+a[j];

}

}



}

printf("%lld",d[tar]);

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<vector>

using namespace std;

const int N=1e5+10;

typedef long long LL;



vector<int> v[N];

int a[N];

int b[N];



int dp[1<<15];



int main()

{

    int n,m;

    cin>>n>>m;

    for(int i=1;i<=m;i++)

    {

        cin>>a[i];

        int c;

        cin>>c;

        for(int j=1;j<=c;j++)   

        {

            int u;

            cin>>u;

            u--;

            b[i]|=(1<<u);

        }

        //cout<<b[i]<<endl;

    }





    for(int i=1;i<=m;i++)

    {

        int u=b[i];



        for(int j=0;j<(1<<n);j++)

        {

            if(j==0||dp[j])

            {

                if(dp[u|j])

                {

                    dp[u|j]=min(dp[u|j],dp[j]+a[i]);

                }

                else

                {

                    dp[u|j]=dp[j]+a[i];

                }

            }

        }

    }



    if(dp[(1<<n)-1])

        cout<<dp[(1<<n)-1]<<endl;

    else

        cout<<-1<<endl;

    



    

    //system("pause");

}

// Faster C++ solution for the same problem (measured speedup: 11.447261057336561x):
#include<cstring>

#include<algorithm>

#include<cstdio>

#define N 10005

#define INF 0x3f3f3f3f

using namespace std;

long long int d[N];

long long int a[1005];

int v[15];

int s[10005];

int b[1005];

int c[15];

int n;

int m;

int tar;

long long int ans=INF;

int main(){

scanf("%d%d",&n,&m);

//for(int i=1;i<=n;i++){

//l[i][0]=0;

//}

memset(d,0x3f,sizeof(d));

memset(v,0,sizeof(v));

memset(s,0,sizeof(s));



for(int i=1;i<=m;i++){

int x,y;

scanf("%lld%d",&a[i],&y);

int st=0;

for(int j=1;j<=y;j++){

scanf("%d",&c[j]);

v[c[j]]++;

st+=(1<<(c[j]-1));

}

b[i]=st;

}

tar=0;

for(int i=1;i<=n;i++){

tar+=(1<<(i-1));

if(v[i]==0){

printf("-1");

return 0;

}

}

d[0]=0;

for(int i=0;i<=tar;i++){

for(int j=1;j<=m;j++){

if(d[i|b[j]]>d[i]+a[j]){

d[i|b[j]]=d[i]+a[j];

}

}



}

printf("%lld",d[tar]);

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int mod=1e9+7;

ll m,n,yy[3005],money[3005],dp[10005],vis[20]; 



int main()

{

    std::ios::sync_with_stdio(0); std::cin.tie(0);

    cin>>m>>n;

    for(int i=1;i<=5000;++i) dp[i]=1e15;

    ll a=1<<m,b,c;

    for(int i=0;i<n;++i)

    {

    	cin>>money[i]>>yy[i];

    	ll s=0;

    	for(int j=1;j<=yy[i];++j) 

    	{

    		cin>>b;vis[b]=1;

    		s+=1<<(b-1);

		}

		yy[i]=s;

	}

	for(int i=1;i<=m;++i) if(!vis[i]) {cout<<-1; return 0;} 

	for(int i=0;i<a-1;++i)

	{

		for(int j=0;j<n;++j)

		{

			dp[i|yy[j]]=min(dp[i|yy[j]],dp[i]+money[j]);

		}

	}

	cout<<dp[a-1];

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.4080662006974234x):
#include<cstring>

#include<algorithm>

#include<cstdio>

#define N 10005

#define INF 0x3f3f3f3f

using namespace std;

long long int d[N];

long long int a[1005];

int v[15];

int s[10005];

int b[1005];

int c[15];

int n;

int m;

int tar;

long long int ans=INF;

int main(){

scanf("%d%d",&n,&m);

//for(int i=1;i<=n;i++){

//l[i][0]=0;

//}

memset(d,0x3f,sizeof(d));

memset(v,0,sizeof(v));

memset(s,0,sizeof(s));



for(int i=1;i<=m;i++){

int x,y;

scanf("%lld%d",&a[i],&y);

int st=0;

for(int j=1;j<=y;j++){

scanf("%d",&c[j]);

v[c[j]]++;

st+=(1<<(c[j]-1));

}

b[i]=st;

}

tar=0;

for(int i=1;i<=n;i++){

tar+=(1<<(i-1));

if(v[i]==0){

printf("-1");

return 0;

}

}

d[0]=0;

for(int i=0;i<=tar;i++){

for(int j=1;j<=m;j++){

if(d[i|b[j]]>d[i]+a[j]){

d[i|b[j]]=d[i]+a[j];

}

}



}

printf("%lld",d[tar]);

}
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<cstring>

#include<algorithm>

#include<cmath>

#include<map>

#include<set>

#include<vector>

using namespace std;

#define ll long long

#define db double

ll dp[1<<12+5];

ll a[1005];

ll key[1005];

ll pow2[15];



int main()

{

    ll n,m;



    pow2[0]=1;

    for(ll i=1;i<15;i++)pow2[i]=pow2[i-1]<<1;

    memset(dp,1e9+5,sizeof(dp));



    scanf("%lld %lld",&n,&m);



    dp[0]=0;



    for(ll i=1;i<=m;i++)

    {

        ll b,t=1;

        scanf("%lld %lld",&a[i],&b);

        for(ll j=1;j<=b;j++)

        {

            ll tmp;

            scanf("%lld",&tmp);

            key[i]=key[i]+pow2[tmp-1];

        }

    }



    for(ll j=0;j<pow2[n];j++)

    {

        for(ll i=1;i<=m;i++)

        {

            dp[j|key[i]]=min(dp[j]+a[i],dp[j|key[i]]);

        }

    }





    if(dp[pow2[n]-1]>=1e9+5)

    {

        printf("-1");

        return 0;

    }

    printf("%lld",dp[pow2[n]-1]);

    return 0;

}






// Faster C++ solution for the same problem (measured speedup: 2.0709677802867623x):
#pragma GCC optimize (3)

#include<vector>

#include<stack>

#include<bitset>

#include<cstdlib>

#include<cmath>

#include<set>

#include<list>

#include<deque>

#include<map>

#include<queue>

#include<iostream>

#include<cstdio>

#include<cstring>

#include<iomanip>

#include<algorithm>

#include<unordered_map>

/*#include<ext/pb_ds/assoc_container.hpp>

#include<ext/pb_ds/tree_policy.hpp>

#include<ext/pb_ds/hash_policy.hpp>

#include<ext/pb_ds/trie_policy.hpp>

#include<ext/pb_ds/priority_queue.hpp>*/

//#include<ext/rope>

#define ll long long

#define ull unsigned long long

#define INFI 2147483647

#define INFL 9223372036854775807

#define INFU 18446744073709551615

#define maxn 1005

using namespace std;

//using namespace __gnu_pbds;

//using namespace __gnu_cxx;

const double PI=acos(-1.0);

const double eps=1e-6;

int a[maxn],sta[maxn],dp[maxn][5000];

inline int read()

{

    int x=0,f=1;

    char ch=getchar();

    while(ch<'0' || ch>'9'){

        if(ch=='-') f=-1;

        ch=getchar();

    }

    while(ch>='0' && ch<='9'){

        x=x*10+ch-'0';

        ch=getchar();

    }

    return x*f;

}

template<typename T> void debug(T x)

{

    cout<<"value="<<x<<endl;

    return;

}

signed main()

{

	//ios_base::sync_with_stdio(false);

    //cin.tie(0);

    //cout.tie(0);

    int n=read(),m=read();

    for(int i=1;i<=m;i++){

        a[i]=read();

        int b=read();

        for(int j=1;j<=b;j++){

            int c=read();

            c=1<<(c-1);

            sta[i]|=c;

        }

    }

    for(int i=0;i<=m;i++) for(int j=1;j<(1<<n);j++) dp[i][j]=100000001;

    for(int i=1;i<=m;i++){

        for(int j=0;j<(1<<n);j++){

            dp[i][j|sta[i]]=min(dp[i][j|sta[i]],dp[i-1][j]+a[i]);

            dp[i][j]=min(dp[i][j],dp[i-1][j]);

        }

    }

    if(dp[m][(1<<n)-1]==100000001) printf("-1\n");

    else printf("%d\n",dp[m][(1<<n)-1]);

	return 0;

}
// Slower C++ solution:
//お勉強中

//これは高速ゼータ変換の応用なの？



#include<bits/stdc++.h>

#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 16;

char cn[cm], * ci = cn;

inline int getint() {

	char C = *ci++;

	int A = C - '0';

	while ((C = *ci++) >= '0') A = A * 10 + C - '0';

	return A;

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);



	fread(cn, 1, cm, stdin);



	int N = getint(), M = getint();

	int n = 1 << N;

	int dp[1 << 12];

	rep(i, n) dp[i] = 1e9;



	rep(i, M) {

		int A = getint();

		int B = getint();

		int C = 0;

		rep(j, B) {

			int c = getint();

			C += 1 << (c - 1);

		}

		dp[C] = min(dp[C], A);

	}



	rep(j, N) {

		rep (i, n) {

			if (!(i >> j & 1)) dp[i] = min(dp[i], dp[i | 1 << j]);

		}

	}



	rep1(i, n - 1) {

		for (int j = i - 1 & i; j > 0; j = j - 1 & i) {

			dp[i] = min(dp[i], dp[j] + dp[i ^ j]);

		}

	}



	if (dp[n - 1] >= 1e9) printf("-1");

	else printf("%d", dp[n - 1]);





	Would you please return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.743214470803524x):
//お勉強中

//これは高速ゼータ変換の応用なの？



//#include<bits/stdc++.h>

#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 16;

char cn[cm], * ci = cn;

inline int getint() {

	char C = *ci++;

	int A = C - '0';

	while ((C = *ci++) >= '0') A = A * 10 + C - '0';

	return A;

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);



	fread(cn, 1, cm, stdin);



	int N = getint(), M = getint();

	int n = 1 << N;

	int dp[1 << 12];

	rep(i, n) dp[i] = 1e9;



	rep(i, M) {

		int A = getint();

		int B = getint();

		int C = 0;

		rep(j, B) {

			int c = getint();

			C += 1 << (c - 1);

		}

		dp[C] = min(dp[C], A);

	}



	rep(j, N) {

		rep (i, n) {

			if (!(i >> j & 1)) dp[i] = min(dp[i], dp[i | 1 << j]);

		}

	}



	rep1(i, n - 1) {

		int k = 1 << 31 - __builtin_clz(i);

		for (int j = i - 1 & i; j >= k; j = j - 1 & i) {

			dp[i] = min(dp[i], dp[j] + dp[i ^ j]);

		}

	}



	if (dp[n - 1] >= 1e9) printf("-1");

	else printf("%d", dp[n - 1]);





	Would you please return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define INF 1LL<<62

#define inf 1000000007



int main() {

	ll n,m,a[1005],b[1005],p[13];

	ll cnt=1;

	for(ll i=0;i<13;i++){

		p[i]=cnt;

		cnt*=2;

	}

	cin>>n>>m;

	for(ll i=0;i<m;i++){

		ll x,y;

		cin>>x>>y;

		a[i]=x;

		ll now=0;

		for(ll j=0;j<y;j++){

			ll next;

			cin>>next;

			next--;

			now=now|p[next];

		}

		b[i]=now;

//		cout <<now<<endl;

	}

	ll dp[100000];

	for(ll i=0;i<100000;i++){

		dp[i]=INF;

	}

	dp[0]=0;

	for(ll i=0;i<100000;i++){

		for(ll j=0;j<m;j++){

			ll cost=a[j];

			ll op=b[j];

			ll next=i|op;

			if(next<100000){

			dp[next]=min(dp[next],dp[i]+cost);

			}

		}

	}

//	cout << ll(pow(2,n))-1;

	if(dp[ll(pow(2,n))-1]==INF){

		cout <<-1;

		return 0;

	}

	cout <<dp[ll(pow(2,n))-1];

	// your code goes here

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.8329701024936425x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define INF 1LL<<62

#define inf 1000000007



ll dp[4200];

int main() {

	for(ll i=0;i<4200;i++){

		dp[i]=INF;

	}

	dp[0]=0;

	ll n,m;

	cin>>n>>m;

	for(ll i=0;i<m;i++){

		ll x,y;

		cin>>x>>y;

		ll op=0;

		for(ll j=0;j<y;j++){

			ll now;

			cin>>now;

			now--;

			now=pow(2,now);

			op=op|now;

		}

		for(ll j=0;j<4200;j++){

			if(ll(j|op)<4200){

			dp[j|op]=min(dp[j]+x,dp[j|op]);

			}

		}

	}

	ll ans=0;

	for(ll i=0;i<n;i++){

	  ans=ans|ll(pow(2,i));

	}

//	cout <<ans<<endl;

if(dp[ans]==INF){

	cout << -1;

	return 0;

}

	cout <<dp[ans];

	// your code goes here

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<math.h>

#include<cstdio>

#include<string>

#include<string.h>

#include<list>

#include<queue>

#include<sstream>

#include<vector>

#include<set>

#include<map>

#include<deque>

#include<stack>

using namespace std;

#define debug(x) cout<<"###"<<x<<"###"<<endl;

const int INF=0x3f3f3f3f,MAXN=1e3+5;

typedef long long ll;

int dp[1<<17];

int cost[MAXN],p[MAXN];

int main(){

	int n,m;

	cin>>n>>m;

	memset(p,0,sizeof(p));

	for(int i=1;i<=m;i++){

		int b;

		scanf("%d%d",&cost[i],&b);

		for(int j=0;j<b;j++){

			int t;

			scanf("%d",&t);

			p[i]|=(1<<(t-1));

		}

	}



	memset(dp,0x3f,sizeof(dp));

//	int N=(1<<n);

//	for(int i=0;i<(1<<n);i++)dp[i][0]=0;

	dp[0]=0;

	for(int i=1;i<=m;i++){

		for(int s=0;s<(1<<n);s++){

			dp[s|p[i]]=min(dp[s]+cost[i],dp[s|p[i]]);

		}

	}



	if(dp[(1<<n)-1]==INF){

		cout<<"-1"<<endl;

	}

	else{

		cout<<dp[(1<<n)-1]<<endl;

	}

	return 0;

}

/*

2 1

30 2

1 2

*/

// Faster C++ solution for the same problem (measured speedup: 1.5039844806210918x):
#include <bits/stdc++.h>

#define endl '\n'

#define fast_in ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define mp  make_pair

#define pb  push_back

#define  sz(x)   (int)x.size()

#define  all(x)  x.begin(), x.end()

#define	 allr(x)  x.rbegin(), x.rend()

#define  bit(x)  __builtin_popcountll(x)

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

typedef pair <int,int> pii;

const int inf = (int) 1e9+99999, mod = (int)1e9+7;

const ll linf = (ll) 2e18+99999;

int mul (int x, int y) { return ((ll)x * y) % mod; } 

int sub (int x, int y) { x -= y; if (x < 0) return x + mod; return x; } 

int add (int x, int y) { x += y; if (x >= mod) return x - mod; return x; }

 

const int maxn = (int) 3e5;





#define int ll



int cost[maxn], k[maxn], c[1001][50];

int d[5001][2];



void solve () {

	int n, m; cin >> n >> m;

	for (int i = 1; i <= m; i ++) {

		cin >> cost[i] >> k[i];

		for (int j = 1; j <= k[i]; j ++) {

			cin >> c[i][j];	

			c[i][j] --;

		}

	}





	for (int mask = 0; mask < (1 << n); mask ++)

		for (int j = 0; j <= n; j ++)

		d[mask][j] = d[mask][j] = linf; 

	d[0][0] = 0;



	for (int i = 1; i <= m; i ++) {

		for (int mask = 0; mask < (1 << n); mask ++)

			d[mask][i] = d[mask][i-1];

		

		for (int mask = 0; mask < (1 << n); mask ++) {

			int mask2 = mask; for (int j = 1; j <= k[i]; j ++) mask2 |= (1 << c[i][j]);

			d[mask2][i] = min (d[mask2][i], d[mask][i-1] + cost[i]);		

		}

	}





	int res = d[(1 << n)-1][m];



	if (res == linf) res = -1;

	cout << res;

}



main () { fast_in;

    int t = 1; //cin >> t;

    while (t --) {

    	solve ();    

    }

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define fs first

#define se second

#define pb push_back

using namespace std;



typedef long long ll;

typedef pair<int,int> pii;

typedef double db;



const int maxn=5e5+5;

const ll inf=0x3f3f3f3f;

const ll mod=1e9+7;



int dp[1<<17];



pii p[maxn];



int main(){

	memset(dp,0x3f,sizeof(dp));

	int n,m;

	scanf("%d%d",&n,&m);

	for(int i=1;i<=m;i++){

		int x,y;

		scanf("%d%d",&x,&y);

		p[i].fs=x;

		for(int j=1;j<=y;j++){

			int k;

			scanf("%d",&k);

			p[i].se|=(1<<k-1);

		}

	}

	dp[0]=0;

	int N=1<<n;

	for(int i=1;i<=m;i++){

		for(int j=0;j<N;j++){

			dp[j|p[i].se]=min(dp[j|p[i].se],dp[j]+p[i].fs);

		}

	}

	if(dp[N-1]==inf) printf("-1");

	else printf("%d\n",dp[N-1]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4812508009970933x):
#include <bits/stdc++.h>



using namespace std;

#define sz(a) int(a.size())

#define ll  long long int

#define mod (long long)(1e9+7)

#define endl '\n'

#define ENGZ ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);cin.tie(0) , cout.tie(0) ;

#define pi (acos(-1))

#define F first

#define S second



ll fp(ll n , ll p )

{

    if(p==0)

        return 1;

    if(p==1)

        return n ;

    ll res = fp(n,p/2);

    res=((res)*(res)) ;

    if(p%2)

        res=(res*n) ;

    return res ;

}



ll n , m , a,  b , c , cnt = 0 , cost = 0;

map<ll,ll> mp;

int main()

{

    ENGZ;

    cin>>n >>m ;

    mp[0] = 0 ;

    for(int i=0 ; i<m ; i++)

    {

        cin>>a >>b ;

        cnt = 0 ;

        for(int i=0 ; i<b ; i++)

        {

            cin>>c ;

            cnt+= fp(2,c-1); // to change digit of mask ..

        }

        for(auto i:mp)

        {

            ll mask = i.F | cnt;

            if(mp.count(mask))mp[mask] = min(mp[mask],i.S + a);

            else mp[mask] = i.S + a;

        }

    }

    ll a5er_box = fp(2,n) -1;

    for(auto i:mp)cerr<<i.F <<" " <<i.S <<endl ;

    cerr<<"---------------------------" <<endl ;

    if(mp.count(a5er_box))cout<<mp[a5er_box] <<endl;

    else cout<<-1 <<endl ;

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define fs first

#define se second

#define pb push_back

using namespace std;



typedef long long ll;

typedef pair<int,int> pii;

typedef double db;



const int maxn=5e5+5;

const ll inf=0x3f3f3f3f;

const ll mod=1e9+7;



int dp[1<<17];



pii p[maxn];



int main(){

	memset(dp,0x3f,sizeof(dp));

	int n,m;

	scanf("%d%d",&n,&m);

	for(int i=1;i<=m;i++){

		int x,y;

		scanf("%d%d",&x,&y);

		p[i].fs=x;

		for(int j=1;j<=y;j++){

			int k;

			scanf("%d",&k);

			p[i].se|=(1<<k-1);

		}

	}

	dp[0]=0;

	int N=1<<n;

	for(int i=1;i<=m;i++){

		for(int j=0;j<N;j++){

			dp[j|p[i].se]=min(dp[j|p[i].se],dp[j]+p[i].fs);

		}

	}

	if(dp[N-1]==inf) printf("-1");

	else printf("%d\n",dp[N-1]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.487574748330718x):
#include <stdio.h>

#include <iostream>

#include <queue>

#include <cstdio>

#include <stack>

#include <algorithm>

#include <cmath>

#include <cstring>

#include <string.h>

#include <limits.h>

#include <map>

#include <string>

#include <bitset>

#include <vector>

using namespace std;

int ans[20000],p[1005],can[1005];

int main() {

    int n,m,a,b;

    cin>>n>>m;

    for(int i=1;i<=m;i++)

    {

        scanf("%d%d",&a,&b);

        p[i]=a;

        int t;

        for(int j=0;j<b;j++)

        {

            scanf("%d",&t);

            can[i]+=pow(2,t-1);

        }

    }

    for(int i=0;i<pow(2,n);i++) ans[i]=INT_MAX;

    ans[0]=0;

    for(int i=1;i<=m;i++)

        for(int j=0;j<pow(2,n);j++) {

            if (ans[j] == INT_MAX) continue;

            ans[j | can[i]] = min(ans[j | can[i]], ans[j] + p[i]);

        }

    if(ans[int(pow(2,n))-1]==INT_MAX) printf("-1\n");

    else printf("%d\n",ans[int(pow(2,n))-1]);

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define fs first

#define se second

#define pb push_back

using namespace std;



typedef long long ll;

typedef pair<int,int> pii;

typedef double db;



const int maxn=5e5+5;

const ll inf=0x3f3f3f3f;

const ll mod=1e9+7;



int dp[1<<17];



pii p[maxn];



int main(){

	memset(dp,0x3f,sizeof(dp));

	int n,m;

	scanf("%d%d",&n,&m);

	for(int i=1;i<=m;i++){

		int x,y;

		scanf("%d%d",&x,&y);

		p[i].fs=x;

		for(int j=1;j<=y;j++){

			int k;

			scanf("%d",&k);

			p[i].se|=(1<<k-1);

		}

	}

	dp[0]=0;

	int N=1<<n;

	for(int i=1;i<=m;i++){

		for(int j=0;j<N;j++){

			dp[j|p[i].se]=min(dp[j|p[i].se],dp[j]+p[i].fs);

		}

	}

	if(dp[N-1]==inf) printf("-1");

	else printf("%d\n",dp[N-1]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.512281410320921x):
#include <iostream>

#include <cstring>

using namespace std;

const int inf = 1e9;

struct key{

    int cost;

    int box;

} k[1005];

int n;

int cs[1 << 12];



int main() {

    int m;

    cin >> n >> m;

    for (int i = 0; i < m; i++) {

        k[i].box = 0;

    }

    int mx = (1 << n) - 1;

    for (int i = 1; i <= mx; i++) {

        cs[i] = inf;

    }

    for (int i = 0; i < m; i++) {

        int a, b;

        cin >> a >> b;

        k[i].cost = a;

        int tmp;

        for (int j = 0; j < b; j++) {

            scanf("%d", &tmp);

            k[i].box += 1 << (tmp - 1);

        }

        cs[k[i].box] = min(cs[k[i].box], a);

    }

    for (int i = 0; i < m; i++) {

        for (int j = 1; j <= mx; j++) {

            int uni = k[i].box | j;

            if (cs[j] != inf && uni != j) {

                cs[uni] = min(cs[uni], cs[j] + k[i].cost);

            }

        }

    }

    if (cs[mx] != inf) cout << cs[mx];

    else cout << -1;

}