#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf (long long)2000000000 int main(){ int N,K; cin>>N>>K; vector A(N),M(N); vector> B(N); rep(i,N){ cin>>A[i]>>M[i]; B[i].resize(M[i]); rep(j,M[i]){ cin>>B[i][j]; B[i][j]--; } } mcf_graph G(N); rep(i,N-1){ G.add_edge(i,i+1,100,Inf); } rep(i,N){ rep(j,B[i].size()){ int x = B[i][j]; int y = i; G.add_edge(x,y,1,Inf*(y-x) - (-A[x]+A[y])); } } long long ans = G.flow(0,N-1,K).second; rep(i,K){ ans -= Inf*(N-1); } ans *= -1; cout<