#include <iostream.h>

// using namespace std;

#include <stdlib.h>

//#define REDIRECT

#ifdef _DOS
const int MAXN=1000, MAXM=1000;
#else
const int MAXN=30000, MAXM=200000;
#endif

#ifdef _DOS
typedef int bool;
#define true 1
#define false 0
#endif

template<class T> T max(T x, T y) {return (x>y)?x:y;};

const long INFTY=1000000000;

int all_lists[MAXM];
int list_len[MAXN], status[MAXN];
size_t list_start[MAXN];

int N,the_last_op;
bool CYCLE_FOUND=false;

long op_time[MAXN], time_res[MAXN], time_max_son[MAXN];

void ReadData(istream &in)
{
int MAIN_K=0;
int the_op;
int i,k;
in >> N;
in >> the_last_op;
for(i=0;i<N;i++)
 {
 in >> the_op;
 status[the_op]=0;
 in >> op_time[the_op] >> list_len[the_op];
 list_start[the_op]=MAIN_K;
 for(k=0;k<list_len[the_op];k++,MAIN_K++)
  in >> all_lists[MAIN_K];
 }
}

long BuildTimes(int the_op)
{
if(status[the_op]==2)
 return time_res[the_op];
status[the_op]=1;
time_max_son[the_op]=0;
for(int k=0;k<list_len[the_op];k++)
 {
 if(CYCLE_FOUND)
  return INFTY;
 int the_u = all_lists[list_start[the_op]+k];
 if(status[the_u] == 1)
  {
  CYCLE_FOUND = true;
  return INFTY;
  }
 time_max_son[the_op] = max(time_max_son[the_op], BuildTimes(the_u));
 }
status[the_op]=2;
return (time_res[the_op] = time_max_son[the_op] + op_time[the_op]);
}

void output_critical(int the_op)
{
status[the_op]=3;
for(int k=0; k<list_len[the_op]; k++)
 {
 int the_u = all_lists[list_start[the_op]+k];
 if(status[the_u]==2 && time_res[the_u]==time_max_son[the_op])
  output_critical(the_u);
 }
cout << ' ' << the_op;
}


int main(void)
{
#ifdef REDIRECT
 {
 ifstream fin("techn.dat");
 ReadData(fin);
 fin.close();
 }
#else
ReadData(cin);
#endif


long res_time = BuildTimes(the_last_op);
if(CYCLE_FOUND)
 cout << "-1\n";
else
 {
 cout << res_time;
 output_critical(the_last_op);
 cout << endl;
 }
return 0;
}