#include<bits/stdc++.h>
using namespace std;
int c,T,n,k,t;
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d%d",&c,&T);
	while(T--)
	{
		cin>>n>>k;
		for(register int i=1;i<n;++i)
		{
			int x,y;
			scanf("%d%d",&x,&y);
			if(y==x+1) t++;
		}
		if(t==n-1) printf("1\n");
	}
	return 0;
}
