#include<iostream>
#include<cstdio>
#include<cassert>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<vector>
#include<cstring>
#include<string>
#include<map>
#include<set>

#define mp make_pair
#define scn second
#define frs first
#define pb push_back

#define NAME "riot"

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, int> pi;
const int P = 239017;
const ll INF = 10000000000000000ll;

int n, k;

int was[1 << 16][51];
ll dp[1 << 16][51];
ll c[51], sz[51];
int gr[51], f[1 << 16];

ll go(int mask, int last) {
	if (mask == (1 << n) - 1)
		return 0;
	if (was[mask][last])
		return dp[mask][last];
	was[mask][last] = 1;
	ll ans = INF;
	int begin = f[mask];
	if (c[last] >= sz[begin]) {
		int newmask = mask | (1 << gr[begin]);
		ans = go(newmask, f[newmask]) + c[last];
	}

	for (int i = 1; i <= k; ++i) {
		if (!(mask & (1 << gr[i])) && i != begin) {
			if (c[last] >= sz[i]) {
			    ans = min(ans, go(mask | (1 << gr[i]), i) + c[last]);
			}
		}
	}

	return dp[mask][last] = ans;
}



int main(){
    freopen(NAME ".in", "r", stdin);
    freopen(NAME ".out", "w", stdout);
	scanf("%d%d", &n, &k);
	int cnt = 1;
	for (int i = 0; i < n; ++i) {
		int t;
		scanf("%d", &t);
		for (int j = 0; j < t; ++j)
			scanf("%I64d", &c[cnt]), gr[cnt++] = i;
   	}
    for (int mask = 0; mask < 1 << n; ++mask) {
    	int now = 0;
    	for (int i = 1; i <= k; ++i) {
    		if (!((1 << gr[i]) & mask) && (now == 0 || c[i] > c[now]))
    			now = i;
    	}
    	f[mask] = now;
    }
    for (int now = 1; now <= k; ++now) {
    	ll sum = 0;
    	for (int i = 1; i <= k; ++i)
    		if (gr[i] == gr[now])
    			sum += c[i];
       	sz[now] = sum - c[now];
    }
    ll ans = go(0, f[0]);
    if (ans >= INF)
    	printf ("-1");
    else
    	printf("%I64d", ans);
    return 0;
}





/*
5 18
1 827
3 20 944 873
1 858
2 896 163
11 5 2024 269 401 14 4974 689 25 962 1 8
*/
