#include
#include
using namespace std;
#define N 1005
vector G[N];
int n,m,c,d,e,x=0,s[N],t[N],in[N],b[N];
char a[N][N];
int main(){
scanf("%d%d",&n,&m);
while(m--){
scanf("%d",&c);
for(int i=1;i<=c;i++)scanf("%d",&s[i]);
d=0;
for(int i=1;i
#include
#include
#include
using namespace std;
#define N 1005
vector G[N];
queue Q;
int n,m,c,d,e,x=1,s[N],t[N],in[N],lv[N];
char a[N][N];
int main(){
scanf("%d%d",&n,&m);
while(m--){
scanf("%d",&c);
for(int i=1;i<=c;i++)scanf("%d",&s[i]);
d=0;
for(int i=1;i
//建图也能超时?
#include
#include
#include
using namespace std;
#define N 1005
vector G[N];
queue Q;
int n,m,c,d,e,x=1,s[N],t[N],in[N],lv[N];
bool find(int u,int v){
for(int i=0;i
var s,t,i,j,k,l,m,n,s2,ans,ss:longint; a,x:array[0..1020,0..1020]of longint; d,Q,t1,t2,lv:array[0..1020]of longint; bo:boolean; begin readln(n,m); for i:=1 to m do begin read(s); for j:=1 to s do read(t1[j]); s2:=0; for j:=1 to s-1 do for k:=t1[j]+1 to t1[j+1]-1 do begin inc(s2);t2[s2]:=k; end; for j:=1 to s do for k:=1 to s2 do a[t1[j],t2[k]]:=1; end; for i:=1 to n do for j:=1 to n do if a[i,j]=1 then begin inc(d[j]); inc(x[i,0]); x[i,x[i,0]]:=j; end; s:=0; t:=0; for i:=1 to n do if d[i]=0 then begin Q[s]:=i; inc(s); end; while(s>t) do begin for i:=1 to x[Q[t],0] do begin dec(d[x[Q[t],i]]); if d[x[Q[t],i]]=0 then begin Q[s]:=x[Q[t],i]; lv[Q[s]]:=lv[Q[t]]+1; inc(s); end; end; inc(t); end; writeln(lv[Q[t-1]]+1); end.