#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include #include using namespace std; using namespace atcoder; const ll INF=1e18+7; int main(){ int n; ll m; cin>>n>>m; mf_graph graph(500); ll sum=0; for(int i=1;i<=n;i++){ int k; ll c; cin>>k>>c; if(m-c>=0){ sum+=m-c; graph.add_edge(0,i,m-c); graph.add_edge(i,n+1,0); } else{ graph.add_edge(0,i,0); graph.add_edge(i,n+1,c-m); } if(k==0) continue; vector A(k); vector B(k); rep(j,k) cin>>A[j]; rep(j,k) cin>>B[j]; rep(j,k){ int t=20*i+A[j]+30; sum+=B[j]; graph.add_edge(0,t,B[j]); graph.add_edge(t,i,INF); graph.add_edge(t,A[j],INF); } } cout<