#include<bits/stdc++.h>usingnamespacestd;intN,M;vector<vector<int>>inputV;vector<int>ans;boolcheck(intx){vector<vector<int>>adj(N+1);vector<int>inDegree(N+1,0);for(inti=0;i<x;i++){for(intj=1;j<inputV[i].size();j++){adj[inputV[i][j-1]].push_back(inputV[i][j]);inDegree[inputV[i][j]]++;}}priority_queue<int,vector<int>,greater<int>>pq;for(inti=1;i<N+1;i++){if(!inDegree[i]){pq.push(i);}}if(pq.empty()){returnfalse;}intturns=0;while(!pq.empty()){turns++;intnode=pq.top();pq.pop();ans[turns]=node;for(intchild:adj[node]){inDegree[child]--;if(inDegree[child]==0){pq.push(child);}}}if(turns!=N){returnfalse;}returntrue;}intbinary_search(){intl=0;intr=M-1;while(l!=r){intmid=(l+r+1)/2;if(check(mid)){l=mid;}else{r=mid-1;}}// make sure to double check l!check(l);returnl;}intmain(){ifstreamcin("milkorder.in");ofstreamcout("milkorder.out");cin>>N>>M;ans.resize(N+1);inputV.resize(M);// read in inputfor(inti=0;i<M;i++){intv;cin>>v;for(intj=0;j<v;j++){intval;cin>>val;inputV[i].push_back(val);}}// run binary searchbinary_search();// print answerfor(inti=1;i<N;i++){cout<<ans[i]<<" ";}cout<<ans[N];cout<<endl;}