#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<limits>
#include<climits>
#include<cmath>
#include<functional>
#include<ctime>
#include<cstdlib>
#include<fstream>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef short int i16;
typedef unsigned long long int u64;
typedef unsigned int u32;
typedef unsigned short int u16;
typedef unsigned char u8;
FILE *IN = fopen("buffet.in","r");
FILE *OUT = fopen("buffet.out","w");
const int N = 1024;
int n;
ll e;
ll min_path[N][N];
queue <int> q;
bool used[N];
int grass[N];
vector <int> v[N];
ll state[N];
void input() {
fscanf(IN, "%d %lld", &n, &e);
int i,d,j,p;
for(i=1;i<=n;i++) {
fscanf(IN, "%d %d", &grass[i], &d);
for(j=0;j<d;j++) {
fscanf(IN, "%d", &p);
v[i].push_back(p);
}
}
}
void BFS(int starting_node) {
memset(used,0,sizeof(used));
while(!q.empty()) {
q.pop();
}
q.push(starting_node);
used[starting_node]=true;
min_path[starting_node][starting_node]=0;
int i,curr;
while(!q.empty()) {
curr=q.front();
q.pop();
for(i=0;i<v[curr].size();i++) {
if(!used[v[curr][i]]) {
used[v[curr][i]]=true;
q.push(v[curr][i]);
min_path[starting_node][v[curr][i]]=1+min_path[starting_node][curr];
}
}
}
for(i=1;i<=n;i++) {
min_path[starting_node][i]*=e;
}
}
void initialize_distances() {
int i;
for(i=1;i<=n;i++) {
BFS(i);
}
}
ll recurse(int last_node) {
if(used[last_node]) {
return state[last_node];
}
int next_node;
ll ans=0;
for(next_node=1;next_node<=n;next_node++) {
if(grass[next_node]<=grass[last_node] || min_path[last_node][next_node]==0) {
continue;
}
ans=max(ans,grass[next_node]-min_path[last_node][next_node]+recurse(next_node));
}
used[last_node]=true;
state[last_node]=ans;
return ans;
}
void solve() {
initialize_distances();
memset(used,0,sizeof(used));
ll ans=0;
int i;
for(i=1;i<=n;i++) {
ans=max(ans,grass[i]+recurse(i));
}
fprintf(OUT, "%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ICBmc2NhbmYoSU4sICIlZCAlbGxkIiwgJm4sICZlKTsKCiAgICBpbnQgaSxkLGoscDsKCiAgICBmb3IoaT0xO2k8PW47aSsrKSB7CiAgICAgICAgZnNjYW5mKElOLCAiJWQgJWQiLCAmZ3Jhc3NbaV0sICZkKTsKCiAgICAgICAgZm9yKGo9MDtqPGQ7aisrKSB7CiAgICAgICAgICAgIGZzY2FuZihJTiwgIiVkIiwgJnApOwogICAgICAgICAgICB2W2ldLnB1c2hfYmFjayhwKTsKICAgICAgICB9CiAgICB9Cn0KCnZvaWQgQkZTKGludCBzdGFydGluZ19ub2RlKSB7CiAgICBtZW1zZXQodXNlZCwwLHNpemVvZih1c2VkKSk7CgogICAgd2hpbGUoIXEuZW1wdHkoKSkgewogICAgICAgIHEucG9wKCk7CiAgICB9CgogICAgcS5wdXNoKHN0YXJ0aW5nX25vZGUpOwogICAgdXNlZFtzdGFydGluZ19ub2RlXT10cnVlOwoKICAgIG1pbl9wYXRoW3N0YXJ0aW5nX25vZGVdW3N0YXJ0aW5nX25vZGVdPTA7CgogICAgaW50IGksY3VycjsKCiAgICB3aGlsZSghcS5lbXB0eSgpKSB7CiAgICAgICAgY3Vycj1xLmZyb250KCk7CiAgICAgICAgcS5wb3AoKTsKCiAgICAgICAgZm9yKGk9MDtpPHZbY3Vycl0uc2l6ZSgpO2krKykgewogICAgICAgICAgICBpZighdXNlZFt2W2N1cnJdW2ldXSkgewogICAgICAgICAgICAgICAgdXNlZFt2W2N1cnJdW2ldXT10cnVlOwogICAgICAgICAgICAgICAgcS5wdXNoKHZbY3Vycl1baV0pOwogICAgICAgICAgICAgICAgbWluX3BhdGhbc3RhcnRpbmdfbm9kZV1bdltjdXJyXVtpXV09MSttaW5fcGF0aFtzdGFydGluZ19ub2RlXVtjdXJyXTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICBmb3IoaT0xO2k8PW47aSsrKSB7CiAgICAgICAgbWluX3BhdGhbc3RhcnRpbmdfbm9kZ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