#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include using namespace std; const ll INF=1e12; struct Edge{ int to; ll w; Edge(int to,ll w) : to(to),w(w) {} }; using Graph=vector>; using pli=pair; template bool chmin(T& a,T b){ if(a>b){ a=b; return true; } return false; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n,k; cin>>n>>k; vector A(n); vector> B; Graph G(n); rep(i,n){ ll a; int m; cin>>a>>m; A[i]=a; rep(j,m){ int b; cin>>b; b--; B.push_back({i,b}); } } for(auto t:B){ ll y=t.first,x=t.second; if(A[x] dist(n,1000000000000000000); int s=0; dist[s]=0; priority_queue,greater> que; que.push({dist[s],s}); while(!que.empty()){ int v=que.top().second; ll d=que.top().first; que.pop(); if(d>dist[v]) continue; for(auto e:G[v]){ if(chmin(dist[e.to],dist[v]+e.w)){ que.push({dist[e.to],e.to}); } } } cout<<(n-1)*INF-dist[n-1]<