#include#include using namespace std;int n,k,fa[1000005],ans;inline int getfa(int v){ return fa[v]==v?v:fa[v]=getfa(fa[v]);}inline void merge(int x,int y){ x=getfa(x);y=getfa(y); if(x!=y)fa[y]=x;}inline bool family(int x,int y){ return getfa(x)==getfa(y);}int main(){ scanf("%d%d",&n,&k); for(int i=1;i<=3*n;i++)fa[i]=i; for(int i=1;i<=k;i++){ int opt,x,y; scanf("%d%d%d",&opt,&x,&y); if(x>n||y>n){ans++;continue;} if(opt==1){ if(family(x,y+n)||family(x,y+2*n)){ans++;continue;} merge(x,y); merge(x+n,y+n); merge(x+2*n,y+2*n); } else{ if(x==y){ans++;continue;} if(family(x+2*n,y)||family(x,y)){ans++;continue;} merge(x+n,y); merge(x,y+2*n); merge(x+2*n,y+n);//是个环:猎物的猎物是天敌 } } printf("%d\n",ans);}//x+n:猎物 x+2*n:天敌